| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Name sounds good to me; i don't think it should be in console at all. Is there any way to have tests that actually verify that the expected colors show up on supported platforms? |
Sorry, something went wrong.
There was a problem hiding this comment.
Left some preliminary comments.
Is there any way to have tests that actually verify that the expected colors show up on supported platforms?
test/parallel/test-util-format.js and test/parallel/test-util-inspect.js might be good places to look for examples.
Also cc @BridgeAR who might be interested since this overlaps with the color support in util.inspect().
Sorry, something went wrong.
There was a problem hiding this comment.
If this is going to be public API, we should probably provide some additional validation for supported formats.
Sorry, something went wrong.
There was a problem hiding this comment.
additional validation
like?
Sorry, something went wrong.
There was a problem hiding this comment.
I was thinking we could validate that format is actually something supported by inspect.colors, but feel free to ignore if you want.
Sorry, something went wrong.
There was a problem hiding this comment.
If they pass anything apart as of now, we are just returning the text as in, do you feel it makes sense to check if the format is supported by inspect.colors and throw an error for non-supported inputs?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, that's what I originally meant.
Sorry, something went wrong.
There was a problem hiding this comment.
Is inspect.colors mutable and exposed to users?
Sorry, something went wrong.
There was a problem hiding this comment.
^ yes!
Sorry, something went wrong.
|
Micro-nit on the commit message: The verb in the first line of the commit message should be imperative. In other words, add rather than adding. This is something that someone can fix when landing, and also no one (not even me) is actually going to care if it slips through as adding rather than add. But if you want to make that change, that would make it comply with our contributor guidelines doc. |
Sorry, something went wrong.
|
Thanks for the clarification @Trott. I had that doubt, fixed it. |
Sorry, something went wrong.
Sorry, something went wrong.
|
We should also add this to the docs right? |
Sorry, something went wrong.
|
Yes, this would require a docs update. |
Sorry, something went wrong.
|
Is this ready enough? |
Sorry, something went wrong.
There was a problem hiding this comment.
Left a few comments. It would be good for others to weigh in on things like the overall API design and whether or not we should make this experimental first.
Sorry, something went wrong.
| added: v18.3.0 | ||
| --> | ||
|
|
||
| * `format` {string} `format` one of the color format from `util.inspect.colors` |
There was a problem hiding this comment.
We should probably link util.inspect.colors to https://nodejs.org/api/util.html#customizing-utilinspect-colors.
Sorry, something went wrong.
| Takes `format` and `text` and retuns the colored text form | ||
|
|
||
| ```js | ||
| const util = require('node:util'); |
There was a problem hiding this comment.
Can you remove this line. Otherwise we'll need to show the same example code for CJS and ESM.
Sorry, something went wrong.
| const util = require('node:util'); | ||
|
|
||
| console.log(util.colorText('red', 'This text shall be in red color')); | ||
| // ^ '\u001b[31mThis text shall be in red color\u001b[39m' |
There was a problem hiding this comment.
| // ^ '\u001b[31mThis text shall be in red color\u001b[39m' | |
| // ^ '\u001b[31mThis text shall be colored red\u001b[39m' |
Sorry, something went wrong.
There was a problem hiding this comment.
s/shall be/is?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, that's what I originally meant.
Sorry, something went wrong.
| assert.throws(() => { | ||
| util.colorText('red', undefined); | ||
| }, { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| message: 'The "text" argument must be of type string. Received undefined' | ||
| }); |
There was a problem hiding this comment.
Wouldn't this already be tested on line 20 when invalidOption is undefined?
Sorry, something went wrong.
There was a problem hiding this comment.
Right, this should rather be util.colorText(undefined, undefined);
Sorry, something went wrong.
| const util = require('node:util'); | ||
|
|
||
| console.log(util.colorText('red', 'This text shall be in red color')); | ||
| // ^ '\u001b[31mThis text shall be in red color\u001b[39m' |
There was a problem hiding this comment.
s/shall be/is?
Sorry, something went wrong.
There was a problem hiding this comment.
Is inspect.colors mutable and exposed to users?
Sorry, something went wrong.
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
There was a problem hiding this comment.
I am hesitant to add new formatting functionalities to util (console does not seem ideal either). I just opened a something similar API: #43523. It does a bit more by also allowing nested colors, this functionality here does not do that (e.g., colorText('green', 'green ' + colorText('red', 'red') + ' green') would end up being colored: green red defaultColor instead of green red green).
Sorry, something went wrong.
|
Let's throw this into the TSC agenda as part of the discussion for #43523 |
Sorry, something went wrong.
|
Dropping it from the tsc-agenda until #43382 is resolved. |
Sorry, something went wrong.
| added: REPLACEME | ||
| --> | ||
|
|
||
| * `format` {string} A color format defined in `util.inspect.colors`. |
There was a problem hiding this comment.
Accepting string | string[] would be really helpful to e.g. make text both a certain color and underline/italic/bold/... at the same time
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is with reference to the comment in #42770
A few things to finalize before completing this draft PR:
//cc @nodejs/util