6

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?

0

1 Answer 1

12

\61 is the octal code for the 1 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 the xterm documentation.

$ printf '\e[\61m' | od -An -vto1 -tc
 033 133 061 155
 033   [   1   m
$ tput bold | od -An -vto1 -tc
 033 133 061 155
 033   [   1   m

For the default background colour, you'd need \e[49m, not \e[\61m. Those 1 and 49 numbers are meant to be expressed in their decimal string representation, not be the byte value.

1
  • Oh, so I've just been reading it wrong. Sorry.
    – nwp
    Commented Nov 4, 2017 at 11:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .