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

Why are ansi 3/4 bit colors not supported? #844

Open
markus-bauer opened this issue Nov 17, 2023 · 2 comments
Open

Why are ansi 3/4 bit colors not supported? #844

markus-bauer opened this issue Nov 17, 2023 · 2 comments

Comments

@markus-bauer
Copy link

It looks like it's currently not possible to output the standard 3/4 bit colors with crossterm.

I just assumed that crossterm's named colors map to those colors, but they actually use the 8-bit color format.
For example Color::Red, doesn't produces the code 31 or 91, but 5;9:

println!("{:?}", SetForegroundColor(Color::Red).to_string())
"\u{1b}[38;5;9m"

Reference: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit

Color::Red => f.write_str("5;9"),

This is extra confusing since there is a separate Color::Ansi() variant, especially for that.

How can one output these default colors with crossterm?
Why are 8-bit colors used for the 16 default colors?

@thecaralice
Copy link

AFAICS the 8-bit 0x00..0x0F and 3/4-bit colors are equivalent; the linked article mentions that:

As 256-color lookup tables became common on graphic cards, escape sequences were added to select from a pre-defined set of 256 colors:[citation needed]

ESC[38;5;⟨n⟩m Select foreground color      where n is a number from the table below
ESC[48;5;⟨n⟩m Select background color
  0-  7:  standard colors (as in ESC [ 30–37 m)
  8- 15:  high intensity colors (as in ESC [ 90–97 m)
 16-231:  6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
232-255:  grayscale from dark to light in 24 steps

@markus-bauer
Copy link
Author

Sorry, for responding so late.

Yes, the colors are equivalent.

If I remember correctly, my issue was more with the fact that crossterm doesn't let you choose which codes to emit, even though it has separate types for named colors and ansi colors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants