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
util: add %c to ANSI transform for console.log() #49205
base: main
Are you sure you want to change the base?
Conversation
It is, provided it's compatible with node's MIT license (which deno is also licensed under so that's okay.)
Good question. I personally don't see the value and very few people ever feature-requested it. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@jcbhmr very cool, thanks for pushing this forward! |
its been a month lol 😅 what would be the best way to go about getting feedback/progress on this PR? do i need to @ someone? what should i do? anything? just wait? 🤷♀️ idk |
@nodejs/util |
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Upstream some changes from nodejs/node#49205 Signed-off-by: Jordan Harband <ljharb@gmail.com>
(went ahead and filed denoland/deno#20856 to upstream some of these suggestions) |
ok i moved the stuff into a new file inspect_colors.js as suggested. its right next to the inspect.js. hopefully everything is still 🟢 lol. |
There are relevant failures in CI on this. |
heyyy @nodejs/startup, what do i do? should i lazy-load this when a %c thing is encountered? should i add it to the "expected.beforePreExec" (whatever that is)? should I go back to putting it in inspect.js instead of breaking it into a new file? |
@nodejs/startup 👈 that ping works right? is there someone else who i am supposed to ping? idk. it all broke once i moved it to a new file lol. |
ive added it to the test-bootstrap-modules.js safelist to fix the test error |
is there anything else i need to do assuming the ci test passes? @nodejs/util @nodejs/startup |
GH actions finally all passed ✅ |
@nodejs/util |
Is there anything else I need to do? Anyone I need to ping? |
Hi! Do we think this feature would deprecate |
imo no. At least, I would not like to do that in this PR. util.styleText is useful when you want to pass around a single string with all the color info baked into the string as ANSI colors/formatting without remembering the ANSI codes or importing a third party ANSI index/lib. This %c specifier is useful when you want to print a colorful message to the console in a cross platform way that works everywhere and degrades gacefully. These are two slightly different use cases that I think can coexist nicely. This PR is about matching the existing feature set of browser and Bun and Deno in Node.js so that "%c works in all browsers and Bun and Deno but not Node.js" can become "%c works everywhere!" console.log("%cWow this works in any JS console! 😎", "color:green") 👆 That's my goal with this PR |
Thanks for the information. I am +1 on this addition, and I look forward to its future! |
@jasnell (since you helpfully commented earlier a few months ago) I believe I have:
Is there anything else I need to do to get this merged? |
The only thing I could think of might be squashing the commits, but that's not always needed |
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.
Great PR. We do have util.inspect.colors
, instead of providing all of the math calculations, it may be more efficient to use that instead,
Other than that, I am +1 on this change!
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.
in fact since this pr has been made deno has updated their color console code to now use an object that looks exactly like util.inspect.colors lol https://github.com/denoland/deno/blame/2f5a6a8514ad8eadce1a0a9f1a7a419692e337ef/ext/console/01_console.js#L200
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.
Maybe you could add that change to your PR?
@nodejs/console WDYT? |
this is something that I saw already had a closed issue #29605 and I figured I should put my code where my mouth is and open a PR instead of waiting for a long-dead issue response. idk if i should open a new issue instead of a pr first?
I'm also not sure of the policy of nodejs around copying code from other places like from deno. deno already has this %c => ansi thing "solved" so i copied some code from there. idk if this is allowed or what.answered in commentrelevant deno bits:
fix #52350