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

Feature Request: Support "direct" (24bit) escape sequences #17

Open
nevans opened this issue Nov 18, 2021 · 2 comments
Open

Feature Request: Support "direct" (24bit) escape sequences #17

nevans opened this issue Nov 18, 2021 · 2 comments

Comments

@nevans
Copy link

nevans commented Nov 18, 2021

24-bit color RGB escape sequences are also sometimes referred to as "TrueColor"

Example use case: Sometimes logfiles use 24bit RGB color escape sequences to make it easy to identify different entities at a glance e.g. assign different email addresses to different RGB values using a checksum.

...or sometimes people just like to do crazy terminal hacks, e.g:

convert -thumbnail "$(tput cols)" "$image" txt:- |
  awk -F '[)(,:]' '/white/{$9=$10=$11=255}!/^#/{if($2%2){printf"\033[48;2;"pR[$1]";"pG[$1]";"pB[$1]";38;2;"$9";"$10";"$11"m▄"}else{pR[$1]=$9;pG[$1]=$10;pB[$1]=$11}}'
tput sgr0

Either way, supporting the entire RGB color space would be useful. 🙁

The escape sequences used by almost all terminals with 24-bit RGB support are:

ESC[38;2;⟨r⟩;⟨g⟩;⟨b⟩m => Select RGB foreground color
ESC[48;2;⟨r⟩;⟨g⟩;⟨b⟩m => Select RGB background color

E.g. see infocmp tmux-direct | grep seta

@nevans
Copy link
Author

nevans commented Nov 18, 2021

FWIW, my primary use-case for this is grafana/grafana#35588

... but it is occasionally fun to pipe jpgs through imagemagick and awk to output inside a terminal window. ;)

@ian-h-chamberlain
Copy link

ian-h-chamberlain commented Dec 21, 2022

I was looking for something similar although for 8-bit colors rather than 24-bit color, for example:

ansicolor.parse('\u001b[38;5;9merror[E0423]\u001b[0m')

The resulting span seems to be parsed with an unnamed field (??) and undefined: true

{
  "css": "",
  "text": "error[E0423]",
  "code": {
    "value": 0
  },
  "": true,
  "undefined": true
}

I suppose ideally the API for this could match the 24-bit color API in terms of accessing the output RGB, since the values can be derived from the 8-bit color value if it doesn't map to one of the standard 16 base colors (e.g. https://stackoverflow.com/a/27165165/14436105)

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