chalk/supports-color

Do you want to work on this issue?

You can request for a bounty in order to promote it!

No way to force color in browser #132

roman-khazanskii posted onGitHub

As far as I could understand, browser.js ignores any means of color enforcing; FORCE_COLOR is ignored, now way of passing --color - and anyway, browser.js just returns 'false'.

Even though chrome console, for instance, does support ansi-color.

So if I need to force some other library, depending on this one, to give me back colorized output (that I can transform to html with smthn like ansi-html), I have to resort to monkey-patching.


How would you pass --color in the browser?

posted by sindresorhus about 3 years ago

Even though chrome console, for instance, does support ansi-color.

https://github.com/chalk/supports-color/blob/4f459ee311817cfad1332731a2c1060e07b2015e/browser.js#L3

posted by sindresorhus about 3 years ago

How would you pass --color in the browser?

There isn't any, that's exactly what I meant.

Even though chrome console, for instance, does support ansi-color.

Hmm, indeed, however I still got no color for some reason (maybe 'basic' was not enough for the library I was using, not sure).

Anyway, it would be nice if FORCE_COLOR would force color even in the browser; using env variable seems better than monkye-patching.

posted by roman-khazanskii about 3 years ago

@sindresorhus we should make sure we're not bumping up against this: https://blog.chromium.org/2021/05/update-on-user-agent-string-reduction.html

@roman-khazanskii could you paste here the value of navigator.userAgent from your browser?

posted by Qix- about 3 years ago

@Qix- sure - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.113 Safari/537.36'

But I'm afraid you are missing my original point. I didn't actually need colors in my browser console, I wanted to transform ANSI-colored string to HTML (even though my browser console did support color as well, these things are not connected).

posted by roman-khazanskii about 3 years ago

I have no idea what you're asking, then. This library doesn't do that, and none of chalk's code outputs HTML.

posted by Qix- about 3 years ago

I have no idea what you're asking, then. This library doesn't do that, and none of chalk's code outputs HTML.

I know! I just want a way to force color support, that's all :) So other library will give me ANSI-colored text and then I will transform it to HTML.

Sorry if I'm not being very clear from the beginning; I just want to force-enable color support, even in the browser.

posted by roman-khazanskii about 3 years ago

I'm bumping into this now —

chalk.supportsColor is returning false in v4.1.2 in Chrome 103.0.5060.134, and is subsequently not coloring any of the text.

But creating a new custom instance that forces color support with const customChalk = new chalk.Instance({level: 3}); does indeed output colored text.

User agent is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36 for me, which makes isBlinkBasedBrowser return true.

posted by j0hnm4r5 over 2 years ago

Ah, I'm now seeing that Chalk v4 is using supports-color v7, which explicitly disables browser color support in browser.js.

posted by j0hnm4r5 over 2 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests