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

Add TrueColor support #17

Open
docelic opened this issue Apr 3, 2023 · 0 comments
Open

Add TrueColor support #17

docelic opened this issue Apr 3, 2023 · 0 comments

Comments

@docelic
Copy link
Collaborator

docelic commented Apr 3, 2023

Add TrueColor support to Crysterm.

Crysterm uses a related shard TermColors to output color. TermColors is used to blend/mix colors, find nearest color in the palette (round down), etc.

TermColors (and consequently Crysterm) currently use the following approach:

  • Up to 256 colors can be output (256, 16, 8, or 2)
  • You can specify any color from 16M, but it will be rounded down to the most similar one from current palette size
  • Color can be specified by color name (a string like "blue") or a hex string (like "#0000ff")
  • Supported color names come from a list of colors embedded in the code; the list does not correspond exactly to either X11 or W3C colors
  • Color names can also be prefixed with light- or bright-
  • The terminal sequence used to output color is the one that references the 256-color palette

On the other hand, TrueColor uses 16M terminal colors. Information about checking for TC support or escape sequences that need to be printed can be found on:
https://github.com/termstandard/colors
https://mudhalla.net/tintin/info/truecolor/
https://unix.stackexchange.com/questions/404414/print-true-color-24-bit-test-pattern#404415
https://medium.com/@dubistkomisch/how-to-actually-get-italics-and-true-colour-to-work-in-iterm-tmux-vim-9ebe55ebc2be

The most important info is that:

  • 16M colors aren't referencing a palette, the RGB value is output directly
  • Terminal sequence for TrueColor is different than the one for 256 and lower color mode (palette)

So, to add TC support (and do other improvements along the way), the course of action is:

  • Convert TermColors and Crysterm functions to work with hex (Int32) numbers as the native format (so instead of the current string "#0000ff" you would specify 0x0000ff)
  • But still keep support in Crysterm for hex strings and color names (just parse into Int32)
  • Add support for TrueColor term escape sequence, not just 256 palette
  • Keep results of color blending/mixing and terminal sequence values in a cache so they're not always being recalculated
  • Convert TermColors to be suitable for use as a class/struct
  • With TermColors converted to class/struct, accept the colorspace size in the initializer (def initialize(colors))
  • Combine Crysterm/TermColors/Tput so that there is better detection for supported colors, depending on terminal [emulator] in use
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

1 participant