Skip to content
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

console: add support for %c style formatter in console.log() #29605

Closed
humphd opened this issue Sep 18, 2019 · 3 comments
Closed

console: add support for %c style formatter in console.log() #29605

humphd opened this issue Sep 18, 2019 · 3 comments
Labels
console Issues and PRs related to the console subsystem. feature request Issues that request new features to be added to Node.js.

Comments

@humphd
Copy link
Contributor

humphd commented Sep 18, 2019

Node's console currently supports a number of formatters, s, j, d, o, O, i, f. However, it doesn't support %c:

> console.log('%cHello World', 'color:green; background:yellow;')
%cHello World color:green; background:yellow;

The same code in Safari, Firefox, and Chrome does this:

Screen Shot 2019-09-18 at 3 55 58 PM

The Console spec doesn't give a ton of help on what %c should do, other than to say that it "Applies provided CSS."

Obviously there are aspects of this that don't make sense in the terminal vs. a browser, but perhaps some of it does? It would be nice if node's console could do more than ignore %c.

Apologies if this has come up in the past and been rejected. I wasn't able to find a previous discussion.

@devsnek devsnek added console Issues and PRs related to the console subsystem. feature request Issues that request new features to be added to Node.js. labels Sep 18, 2019
@devsnek
Copy link
Member

devsnek commented Sep 18, 2019

Technically possible but we'd need to bring in a CSS parser, map all the ANSI stuff, etc...

What if we just strip out %c formatting entirely:

> console.log('%cHello World', 'color:green; background:yellow;')
Hello World

@jasnell
Copy link
Member

jasnell commented Sep 18, 2019

For now, I'd say stripping out the %c formatting is the better approach.

devsnek added a commit to devsnek/node that referenced this issue Sep 18, 2019
Fixes: nodejs#29605
Refs: https://console.spec.whatwg.org
Co-Authored-By: Anna Henningsen <github@addaleax.net>
targos pushed a commit that referenced this issue Sep 23, 2019
Fixes: #29605
Refs: https://console.spec.whatwg.org
PR-URL: #29606
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
BridgeAR pushed a commit that referenced this issue Sep 25, 2019
Fixes: #29605
Refs: https://console.spec.whatwg.org
PR-URL: #29606
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@jcbhmr
Copy link
Contributor

jcbhmr commented Jul 15, 2023

Is there any interest in pursuing this to make CSS %c colors work in Node.js? Deno has this support, so it's already "been done" in the sense that there's public MIT-licensed code that could be used as a how-it-was-already-done example: https://github.com/denoland/deno/blob/306b51d7728a6e28461171d3332a0b3aa8545a6e/ext/console/01_console.js#L2821-L2926

I think that what would need to change is here: https://github.com/nodejs/node/blob/main/lib/internal/util/inspect.js#L2263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants