Remix.run Logo
teddyh 2 hours ago

No mention whatsoever of the $TERM environment variable. sigh

Outputting raw escape codes and hope that they work is not how you do it. This is not how any reasonable library (or bash, or git, etc.) does it. These programs and libraries start with the $TERM environment variable to find out what terminal the user is using, and then use something like termcap(5) or terminfo(5) to look up what capabilities that specific terminal has, and what actual escape codes to output to get that effect. In reality, though, most regular programs delegate all this to a library, like ncurses.

(And also make sure not to output any terminal codes at all if the standard output is not a terminal, as in isatty(3) or tty(1).)

This way, you can check for and use modern cool stuff like sixels, but not use them if some user is using something older like XTerm or the Windows Console.

tripflag an hour ago | parent | next [-]

Aside from the 256-color section, I believe all of the examples given in the article are basic sequences which are supported in ~every terminal. Are you aware of any notable terminals where that is not the case?

Maybe I've been lucky, but I've written plenty software that blindly shoots CSI's at the console and still haven't hit any snags. Especially convenient when the channel is unidirectional; curl ocv.me :)

shawn_w an hour ago | parent | prev | next [-]

Easy way is to use `tput` to generate the color codes for your terminal type on the fly.

See https://stackoverflow.com/questions/54838578/color-codes-for... for examples.

xyzzy_plugh 2 hours ago | parent | prev | next [-]

Indeed, but also termcap is a tire fire. I like the way Ghostty deals with it: https://ghostty.org/docs/help/terminfo

Even then it still leaves a lot to be desired. I'm not sure I can consider any of this to be truly reasonable.

enriquto 2 hours ago | parent | prev [-]

> No mention whatsoever of the $TERM environment variable. sigh

I have mixed feelings about this... Sometimes I feel young and reckless and want to just output whatever I need without checking $TERM. In practice, all modern terminal emulators are essentially xterm-256color compatible. If something breaks, the worse you get is some funny characters. Is that such a big deal? Much better than propagate the silly termcap/terminfo complexity.

By the way, xterm supports sixels since forever.