-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add optional colors: boolean
flag to Options
#21
Conversation
colors: boolean
flagcolors: boolean
flag to Options
Rebased to resolve the trivial import-name conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rwe!
Appreciate you taking the time to contribute.
@wooorm would probably be the most insightful for reviewing this.
But is both traveling and is in the midst of releasing major versions across most of the 500+ unified ecosystem packages.
Appreciate your patience with the review.
If this is urgent, feel free to ping.
Thanks! It's not urgent, just some tinkering I felt might be useful to contribute. For a little context where I was going with this before getting distracted-from-distractions, was to add a "depth" parameter and then use |
Thanks for your patience!
If we’re getting more options, sure.
Oh nice! Hmm, I also feel the plural This needs docs! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like my review comments were never posted :'( Sorry about that.
* @property {(_: string) => string} green | ||
* Style a non-tree value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you type the function explicitly somewhere? So @callback StyleFunction ...
, and use that in each case here? Then we can describe parameters/return types
* Configuration. | ||
* @returns {string} | ||
* Pretty printed `tree`. | ||
*/ | ||
export function inspectNoColor(tree, options) { | ||
return inspectColor(tree, options).replace(colorExpression, '') | ||
/* c8 ignore next 3 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this ignored? Wouldn’t it be better to add a test?
return inspectColor(tree, options).replace(colorExpression, '') | ||
/* c8 ignore next 3 */ | ||
const optionsWithNoColor = useColorByDefault | ||
? Object.assign({}, options, {colors: false}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using spreads instead of object.assign is fine by me!
* @return string | ||
* The first `count` lines of `text`. | ||
*/ | ||
const lines = (text, count) => text.split('\n').slice(0, count).join('\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe the parameters, use a regular function, and move it to the bottom of the file. (and: use the braces for the return type, {string}
)
@@ -420,6 +430,51 @@ test('inspect()', async function (t) { | |||
].join('\n') | |||
) | |||
}) | |||
|
|||
await t.test('inspect(…, {colors: false})', async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await t.test('inspect(…, {colors: false})', async function () { | |
await t.test('should support `colors: false`', async function () { |
}) | ||
|
||
await t.test( | ||
'inspect(…, {colors?: true | null | undefined})', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'inspect(…, {colors?: true | null | undefined})', | |
'should support `colors: true` (default)', |
Initial checklist
Description of changes
Previously,
inspect()
would always add ANSI color sequences when on Node and always omit them otherwise.inspectNoColor()
andinspectColor()
were exported to override this, but that was a little bit clunky. This adds an optionalcolors: boolean
flag toOptions
. (Note that this is the same flag name as innode:util
'sinspect
).The default behaviour is unchanged: this feature is purely additive.
Internally, this also introduces the colorization/stylization functions to
State
, allowing the no-color path to simply omit colorization, rather than stripping ANSI sequences after the fact.