How does asciinema capture and reinterpret colors?

Hi Asciinema —

First, thanks for this terrific piece of technology—I love it!

I’m trying to better understand how the colors displayed in my terminal during recording relate to those that are used during playback. From my limited experience so far, I’m finding that some colors that I’ve set (e.g., those used to highlight strings or comments in emacs) tend to be preserved during playback, while others (e.g., the one set in PS1 for entering commands, or for keywords in emacs) are not. I understand that the themes used by asciinema need to be able to influence which colors are used during playback, but am having trouble understanding why some choices I make seem to stick, but not others. Or maybe more to the point: I’m having trouble with color decisions I’ve made in my local environment looking good in the asciinema themes (and am not certain I want to go so far as to invent a new asciinema theme myself).

Related: I tend to use a terminal with a white background, but have been unable to find a theme that preserves that. I thought when I was cycling through the five themes the other day, I did find one, but today they all seem to have dark backgrounds other than solarized-light (?).

Thanks for any help here,
-Brad

I am not affiliated with the platform but i would say than ansi escapes captured from terminal are likely being processed via javascript wizardry into a 256 color palette that your browser is likely to interpret correctly (and accross most if not all of other graphical browsers there is out there)

As far as theme, i really never asked myself the question, probably just figured it would base itself on whatever science there is originally, within a shell’s TERM existing color schemes and themes. Other than that, i guess i also always assumed that only color tints and emphasis (bold/light/tones) and background colors would/were change/d

I am waiting for a reply too, then (for lack of time to investigate on my own)

Im not sure white bg is an actual terminal background color as much as it is a customization option that the specific terminal you use allows you to set, only locally (to you), at runtime with whatever gtk tricks that could apply, while keeping the actual terminal bg color a typical (and well understood) black color.

Again, this is only what goes in my head as i read your post. Interresting questions that will make me learn the basis of older rerminals and their capabilities beyond what i already (rather think) i already know.

Thanks for the question, Hopefuly @ku1ik can shed a light on that or give us pointers with wich we can extrapolate a better answer than only my thoughts! Let us know if you come accross anything in the meantime.

1 Like

Old thread but I think still worth addressing the questions.

Modern terminal emulators typically support:

  • 8 or 16 color palette, where colors are numbered from 0-7 (0-15), and have known meaning, e.g. 1 is red, 2 is green, 3 is yellow, 4 is blue, etc - this is the color palette defined by popular color schemes
  • predefined 6x6x6 color cube (color numbers 17-255)
  • true color / RGB

When programs in a terminal use the indexed (palette) colors then what asciinema sees and records are the symbolic numbers (1, 3, 6, …), not actual RGB values. Those are probably the colors where you sometimes see a mismatch when replaying in a browser.

When programs emit the higher indexed colors (17-…) or true color values then asciinema can capture those accurately and render them properly. The ones used in Emacs may be of this type.

Either way, asciinema CLI 2.x wasn’t able to capture the actual color palette of a terminal so the playback in a browser often used a different palette (one of the available themes).

Good news is, the upcoming asciinema 3.0 does capture the original terminal palette (16 colors), embeds it in the cast file under “theme” entry in the header, and the web player correctly uses the original theme.

If you’d like to test this then there are precompiled binaries for Linux and macOS Release v3.0.0-rc.1 · asciinema/asciinema · GitHub, or you can build from source as described here: Testing the new Rust version of the asciinema CLI - #10 by ku1ik

1 Like