-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
lib,test,doc: add option to highlight outputs of warn
and error
methods
#40424
Conversation
/cc @BridgeAR |
I'm trying to find out why test case The CI Action outputs
while on my laptop, the outlines seem correct if I cancel my change to let this test fail and get its output.
|
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 for working on the color support in Node.js!
The current approach would work but I would rather not replace the current coloring with just a single font color. Instead, we could change the background color and or add a sign to the beginning of the output to indicate that it's an error or warning. That way we'd keep the original coloring in place and profit from the stronger warn / error indicator.
As last note: colors are perceived differently around the globe. Red is a positive sign in many Asian countries. See e.g., https://www.shutterstock.com/blog/color-symbolism-and-meanings-around-the-world. So thanks for adding the new style to util.inspect.styles
to allow the users to change that. It just does not feel like the right place to add such option (it won't be used by util.inspect()
and it's an option directly related to it). Instead, please add an option to the console constructor to allow editing that color and document the new option.
Summary:
- Add option to console constructor to allow editing the colors
- Document the option
- Remove
util.inspect.styles
entries - Use a light / dim background color instead of changing the foreground colors
Really valuable suggestions. Thank you @BridgeAR ! I'm happy to take them and re-implement later. |
warn
and error
methods
warn
and error
methodswarn
and error
methods
I just pushed my new implementation, along with necessary tests and documentation. Now we can create const { Console } = require('console');
const logger = new Console({
stdout: process.stdout,
stderr: process.stderr,
highlight: {
warn: { bgColor: 'bgYellowBright' },
error: { bgColor: 'bgRedBright', indicator: '\u274c' },
}
});
logger.warn('Warning!');
// Will output message 'Warning!' along with bright yellow background.
logger.error(new Error('Ah oh!'));
// Will output message 'Ah oh!' along with bright red background,
// and a cross sign in front of the message indicating error.
// I turned down the color brightness of my terminal to make it more readable. It's not enabled by default. Only explicitly pass option Any suggestions are welcome. Thank you! |
I'm generally ok with making the changes discussed here. I just want to make sure that accessibility concerns are being looked at... specifically, will the color schemes chosen by default be problematic for colorblind users? |
Thank you @jasnell. This feature doesn't provide a default color theme. It's not enabled until user sets its colors explicitly. But to be honest, choosing a background color working with multiple foreground colors without losing accessibility is not that easy. It's not only a problem for colorblind users, but also for non-colorblind. As described in my last comment, I have to decrease the brightness of color |
@rayw000 Is this still something that you would like to complete? I'd like to see this feature land, but I'm not sure what the next step would be. Is it ready for review from your perspective? Or is there still an issue with a test behaving differently on your laptop than in CI? |
Thank you @Trott . In my perspective, this PR is ready for review. The differences between my laptop and CI have been solved. Let me make a summary of the current state.
I've just solved the conflicts. We could send it to CI now, if you think this PR is OK. |
1. add option to highlight 'warn' and 'error' messages 2. add necessary unit tests 3. update document
Rebase master and do |
FYI it's better not to force push when there are flaky CI results, it's easier to simply wait for a collaborator to re-spawn them (otherwise all the jobs have to re-run, even the ones that were already green). |
Glad to hear that! |
What changed
console.error
andconsole.warn
.console.error
andconsole.warn
.Fix #40361
Screenshot: