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

24-bit true-color RGB escape codes in iTerm2 #154

Closed
ianthehenry opened this issue Oct 7, 2021 · 11 comments
Closed

24-bit true-color RGB escape codes in iTerm2 #154

ianthehenry opened this issue Oct 7, 2021 · 11 comments

Comments

@ianthehenry
Copy link

ianthehenry commented Oct 7, 2021

For some reason, when using iTerm2 on macOS, RGB escape codes are colon-separated instead of semicolon-separated.

But asciinema-player doesn't know how to parse those, so if you're recording 24-bit color on a mac, you can't play them back with asciinema-player. Here's an example that works great in iTerm2 (and thus local asciinema playback), but that does not work with asciinema-player:

https://asciinema.org/a/DXFd3EAnipwXA2MggYkNhX24g

You can workaround this by creating a custom terminfo database and forcing it to use semicolons, as demonstrated here:

https://stackoverflow.com/questions/14672875/true-color-24-bit-in-terminal-emacs

iTerm2 will still render and display the semicolon-separated escape codes correctly, so there doesn't seem to be any downside to doing this, but it's unfortunate that asciinema-player doesn't work out of the box for 24-bit color recordings on a mac. (And this problem was... very difficult to diagnose.)

The simple fix would be to support either colon-separated and semicolon-separated escape codes in asciinema-player. But I don't really understand... anything about this. So maybe that's not the right thing to do.

@ku1ik
Copy link
Contributor

ku1ik commented Oct 27, 2021

Interesting. So I use iTerm 2 on macOS and it correctly records and replays 24-bit colors for me.

@ku1ik
Copy link
Contributor

ku1ik commented Oct 27, 2021

Using colon instead of semicolon for rgb value separators is something I haven't seen so far. I can't watch the recording you linked because it's now been archived, so not sure what program you run in your recording session that produced these colons.

@ianthehenry
Copy link
Author

I ran:

TERM=xterm-direct asciinema rec --command "emacs" -i 2 --overwrite repro.cast

And got this file:

https://asciinema.org/a/IdqatKnlBkVhgpGNUVjmKnkIy

Which plays back in full color locally, but not on the web.

Setting xterm-direct is necessary to get emacs to use 24-bit color in a terminal, but apparently that terminal is defined with colons? Maybe there's a correct value of TERM that works fine out of the box with semicolon-separated escapes? But if there is I don't know. That was what the internet told me to use. I set one up for myself and everything worked.

Possibly interesting thing: this does work if I run TERM=xterm-direct emacs within a tmux window and then record myself attaching to that. So some kind of nesting terminal emulators causes this to do the right thing? Or tmux is translating from the weird colon-format to the semicolon format?

@ku1ik
Copy link
Contributor

ku1ik commented Feb 20, 2023

This problem seems to be very unusual and likely related to your specific setup.

I'm going to close it, but we can revisit if another poor soul stumbled upon something similar.

@ku1ik ku1ik closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
@rockorager
Copy link

I ran across this issue as well. Colon separated is the preferred method by nearly ever terminal I've encountered.

@ku1ik ku1ik reopened this Aug 9, 2023
@ku1ik
Copy link
Contributor

ku1ik commented Aug 9, 2023

Yeah, I take back what I said earlier. We gotta fix it indeed.

@ku1ik
Copy link
Contributor

ku1ik commented Aug 9, 2023

I need to solve asciinema/avt#9 for this first.

@rockorager
Copy link

rockorager commented Aug 9, 2023

I need to solve asciinema/avt#9 for this first.

I took a look at the code, I'm not much of a rust person so it would take me quite awhile but you can look at alacritty's implementation. I think it's best to use the Params struct with subparam handling. That makes it easy to handle things like:

CSI 38:2::0:0:0;48:2::0:0:0m

Vs

CSI 38:2:0:0:0;48:2:0:0:0m

(Note the double colon for the colorspace attribute, which is often missing)

@ku1ik
Copy link
Contributor

ku1ik commented Aug 9, 2023

Thanks. I'll take a look at their impl.

@ku1ik
Copy link
Contributor

ku1ik commented Oct 16, 2023

I recently created distinct Params struct for collecting params (https://github.com/asciinema/avt/blob/28aed2b5a65a4ff07344fd6bc51b8ccb8542389c/src/parser.rs#L33) which should help implementing sub-param handling.

@ku1ik
Copy link
Contributor

ku1ik commented Jun 15, 2024

This has been fixed in 3.8.0 - https://github.com/asciinema/asciinema-player/releases/tag/v3.8.0

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

3 participants