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
Terminal colors built-in to Node #42770
Comments
I know this isn't what you're asking for exactly, but just in case anyone wants to be able to use these codes right now without a library: List of built-in colors: console.log(util.inspect.colors) Note that despite it being named Creating/using ANSI codes from these: const util = require('util')
const formatTxt = (format, txt) => `\u001b[${format[0]}m${txt}\u001b[${format[1]}m`;
const blue = util.inspect.colors.blue
const italic = util.inspect.colors.italic
console.log(formatTxt(blue, 'This is blue text'))
console.log(formatTxt(italic, 'This is italic text'))
console.log(formatTxt(blue, formatTxt(italic, 'This is blue, italic text'))) A robust library would also likely do things like check the return value of |
console.log already supports colors in Visual Studio Code with warnings and errors highlighted. There is also the %c which works in Visual Studio Code. Doing the same for console output in the command shell (terminal) would be valuable. At the very least, it would match the error handling capabilities found when running under VSC. The problem with using escape sequences is that they often produce spurious output on devices without VT-100 emulation. It would be more consistent to share the same mechanism. |
So does Node.js, although we could do more with color than we do perhaps. Right now, for example, in the following error, strings are highlighted in green and parts of the stack trace that are internal are slightly greyed out a bit, but that's it.
That would require adding CSS support to Node.js, which is neither a small undertaking nor something very likely to happen in the near future. I suppose we could consider supporting a tiny subset of CSS, but I'm inclined to be skeptical of that approach. (UPDATE: I see that
Unless we're going to do what VS Code does and basically ship an entire Chromium browser along with Node.js, I'm not sure there's going to be any getting around those limitations. (Maybe I'm misunderstanding what you mean.) |
Thanks, I see there is already some color capability for error messages. Yes, the subset for VSC is exactly what I want so that it works in both environments without having to depend on particular libraries. The goal is to be able to highlight some messages. As you note, going further is a major step and not necessary for the modest purpose of highlighting messages. |
|
cc @nodejs/util It would be a worthy goal to eliminate the need for colors/chalk; i don’t think new general-purpose formatting APIs are particularly valuable. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
Having to download external libraries like chalk, colors, etc.
This also aids the scenario where programmers are without package managers. Sometimes, one standalone file in JavaScript is best. Implementing this feature would aid those individuals, and also reduce the bundle size because no package managers would have to be used for a simple JavaScript program.
Using Yarn or NPM makes a
node_modules
folder, which is especially large by only adding one dependency just for terminal colors.Hopefully, you take this issue into consideration, and I would be happy to help implement a such feature.
What is the feature you are proposing to solve the problem?
An enumeration of ANSI escape codes for users to easily access to change the color of the terminal.
Example usage of this would be:
What alternatives have you considered?
One alternative (already exists) would be to use a package manager like Yarn or NPM to download a package like 'chalk' or 'colors'.
However, Node.JS users not using package managers would be unable to accomplish this.
The text was updated successfully, but these errors were encountered: