I am trying to write a program that runs a console program like gcc and displays its output in color. I used openpty
instead of pipe
to pretend to be a character device and now get ANSI escape codes that carry color information. I tried some programs and they sometimes give me the code CSI [ 49 m
. Both wikipedia and the xterm escape code documentation (search for Ps = 4 9
) agree that code CSI [ 49 m
means that I should be using the default background color.
However, debian's xterm and zsh as well as ubuntu's linux console disagree.
printf '\033[\061mTest\n\033[\060m'
executed in a console like xterm should be printing "Test" with the default background color (\033
is escape and escape + [
make a CSI (Control Sequence Introducer) and \061
is octal which is 49 decimal), but it actually prints "Test" in bold (and the \061
at the end seems to mean "not bold anymore" but is documented neither on wikipedia nor in the xterm color code documentation). All consoles mentioned above agree on this.
There is a list of color codes for various consoles and standards, but none of them list CSI 49 m
to mean "bold".
Where does this inconsistency come from? Where can I find a list of color codes that correspond to what any of xterm, zsh or the linux console are using?
Best Answer
\61
is the octal code for the1
character in ASCII, so\e[\61m
or\33[\61m
or\33\133\61\155
or\33[1m
is<ESC>[1m
.That's
CSI 1 m
. See Wikipedia or thexterm
documentation.For the default background colour, you'd need
\e[49m
, not\e[\61m
. Those1
and49
numbers are meant to be expressed in their decimal string representation, not be the byte value.