Hacker News
Build your own Command Line with ANSI escape codes (2016)
teddyh
|next
[-]
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) to look up what capabilities that specific terminal has, and what actual escape codes to output to get that effect.
(And also 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.
tl2do
|next
|previous
[-]
esafak
|previous
[-]
klibertp
|root
|parent
[-]
Also not mentioned in the article: there are a few syntaxes available for specifying things in control sequences, like
\x1b[38;2;{r};{g};{b}m
for specifying colors. There's a nice list here: https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f1... You can also cram as many control codes as you want into a control sequence, though it probably isn't useful in a modern context in 99.9% of cases.