Coder Social home page Coder Social logo

Comments (17)

adalinesimonian avatar adalinesimonian commented on June 13, 2024 1

Also, you might want to commit the same fix you made here on chalk/chalk - it has the same exact text in the readme. 👍

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

Black bright is actually it's own color believe it or not. On Windows there are four greyscale shades.

I'll take a look :)

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

Had no idea. Please, by all means, take a look.

Side note: I spent last night trying to get black on yellow to show up nicely on Windows... I wish I could have that time back.

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

What did you try? Are you using chalk or consuming ansi-styles directly?

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

I was using chalk. Even with rgb(0,0,0) I'd get a weird grey-ish hue instead of full black.

Then I made it blue on yellow, and it was legible with both default colours and base16-tomorrow. Go figure!

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

@vsimonian So even with rgb(0, 0, 0) depending on your windows version, that's just going to get encoded down to black 😅. If you're on windows 10, that might be a different story though.

As for the colors in the terminal, if black (rgb(0, 0, 0)) isn't showing up as actual black, it's almost certainly being encoded down to one of the more basic codes.

Which terminal are you using?

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

Yes, Windows 10. I was just trying everything out of desperation. Probably went through every combination of black or black-ish you could think of. Still possible I missed something; I was pretty frustrated!

It works now and I'm afraid to touch it.

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

Is this cmd.exe or some other terminal that you're using? (I know the ticket is closed but I'm still interested in figuring out why it didn't show up as black for you :))

Also thanks for the report. gray is considered blackBright (which are both 90 in this case).

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

Aha, I said it was gray! (C'mon, had to boast a little bit.)

About the colours, I tried everything I could think of: cmd.exe, WSL running in the default Windows command-line shell, WSL running in MinTTY, and VSCode's integrated terminal. All of them were more than happy to give me a disgusting grey instead of black.

I thought it might be artefacts from the font-smoothing mudding up the black text, so I blew up the text size but to no avail. Everything I tried seemed to be entirely inconsistent across terminals, and the one that was legible in all was just using blue on orange with a fallback to a yellow background if there was no 256-bit colour support.

I dug up the code, here it is:

// cli-tags.js

const chalk = require('chalk')

module.exports = {
  /** [ERROR] */
  error: chalk.supportsColor
    ? chalk.bgRed.whiteBright.bold(' ERROR ')
    : '[ERROR]',
  /** [WARNING] */
  warning: chalk.supportsColor                       // this here
    ? (chalk.level > 1                               // is the reason
      ? chalk.bgYellow.bgKeyword('orange').blue.bold // we can't have
      : chalk.bgYellow.blue.bold)(' WARNING ')       // nice things
    : '[WARNING]',
  /** [INFO] */
  info: chalk.supportsColor
    ? chalk.bgBlue.whiteBright.bold(' INFO ')
    : '[INFO]'
}

If you're wondering "why the hell is she using bgYellow.bgKeyword('orange') but then also just uses bgYellow on its own???", the answer is gross.

So on Windows 10 build 15063 (I can't speak for other versions of Windows), when level is 1, bgYellow.bgKeyword('orange') results in this ugly:
image

Just look at that sad grey. Ugly. So I check the level manually, and if it's 1, only pass through the yellow background.

Meanwhile, on the same system, it shows up as orange in MinTTY as expected.

However, with the first line, if you get rid of the bgYellow which seems to be totally redundant, you break the output in VSCode's integrated terminal, and it fails to display any background colour at all. I don't have a screenshot, but just imagine that warning label having a black background, just like the rest of the terminal.

I already have a headache.

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

That's actually super weird. bgKeyword('orange') should be resolving down to yellow in theory within color-convert. keyword -> rgb -> ansi16 (for level 1).

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

Just tested:

> cc.keyword.ansi16('orange')
93

Which is bright yellow (ansi-styles will add 10 to get the background code in this case). So maybe those terminals don't support bright codes? Very strange.

Just curious; what does the following show up as:

chalk.yellowBright.bgBlack.inverse(' WARNING ')

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

Here comes a looooong comment

  • cmd.exe:
    image
  • ConHost/WSL:
    image
  • MinTTY/WSL:
    image
  • VSCode Integrated Terminal/bash.exe:
    image
  • VSCode Integrated Terminal/cmd.exe:
    image

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

What build of Windows 10 are you on?

Conhost doesn't surprise me at all. Don't use it if you want terminal colors IMO.

Anyway, you're right in that cmd.exe should be working.

EDIT: Also, thank you for taking the time to do all of these. It's really appreciated.

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

Version 1703, build 15063

And I agree ConHost is garbage needing of improvement. But I still need to account for users out of my control using ConHost; at the very least they should have legible text (and in this case, while ugly, it is at least still legible).

And don't go thanking me for spamming this issue with pictures - at this point I might as well just be venting. Thanks for looking into the darn thing!

What's interesting to me is that this inverse method actually got me full, solid black on the console whereas before it wasn't really working.

So here's what I put together:

const chalk = require('chalk')

const boldTags = {
  /** [ERROR] */
  error: chalk.supportsColor
    ? chalk.bgRed.whiteBright.bold(' ERROR ')
    : '[ERROR]',
  /** [WARNING] */
  warning: chalk.supportsColor
    ? (chalk.level > 1
      ? chalk.bgYellow.bgKeyword('orange').black.bold
      : chalk.bgYellow.black.bold)(' WARNING ')
    : '[WARNING]',
  /** [INFO] */
  info: chalk.supportsColor
    ? chalk.bgBlue.whiteBright.bold(' INFO ')
    : '[INFO]'
}

const inverseTags = {
  /** [ERROR] */
  error: chalk.supportsColor
    ? chalk.bgWhiteBright.red.inverse.bold(' ERROR ')
    : '[ERROR]',
  /** [WARNING] */
  warning: chalk.supportsColor
    ? (chalk.level > 1
      ? chalk.yellow.keyword('orange').bgBlack.inverse.bold
      : chalk.yellow.bgBlack.inverse.bold)(' WARNING ')
    : '[WARNING]',
  /** [INFO] */
  info: chalk.supportsColor
    ? chalk.blue.bgWhiteBright.inverse.bold(' INFO ')
    : '[INFO]'
}

console.log(`Regular tags:
${boldTags.error}
${boldTags.warning}
${boldTags.info}`)

console.log(`Inverse tags:
${inverseTags.error}
${inverseTags.warning}
${inverseTags.info}`)

And here are the results:

image

Using inverse makes the white-text tags look grey, less bold, and generally more reminiscent of a sad clown, but on the black-text tag it is an absolute masterpiece.

It seems you know something I don't regarding the functionality of inverse.

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

Inverse is its own code, [7m. It's archaic and IMO shouldn't exist anymore, but it does. It tells the emulator to reverse the fore- and background colors under the hood. We're not doing anything special there, and so in certain cases where the foreground bright codes (9x) are supported but the background codes aren't (10x), sometimes inverse works.

It's pretty cross platform compatible in that all terminals on non-windows support it and it has first class support in LibUV (I know because I wrote that support myself 🙂) which means it is supported on windows terminals that respond to the *Console() win32 API calls (which should be all of them).

from ansi-styles.

adalinesimonian avatar adalinesimonian commented on June 13, 2024

I haven't had a chance to have a crack at testing this on my Fedora installation or on my MacBook, but if I get you correctly, you're saying using this archaic code fooled Windows into doing the right thing, but on *nix OSes I would have been most likely getting the correct colour output with just bgYellow.black.bold?

from ansi-styles.

Qix- avatar Qix- commented on June 13, 2024

Correct.

from ansi-styles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.