[C-prog-lang-l] terminal colors

Vladimír Kotal vlada at devnull.cz
Wed Mar 10 10:54:37 CET 2021


Someone had a question about terminal colors in the chat:

  The syntax for changing terminal font color look quite weird, is there
any reason why is it so?
  Example for red: printf("\x1B[31m sometext")


In short, this is something that is not done by C. It merely emits the ESC
control character (0x1B in hexadecimal) followed by the string that
describes the code - see https://en.wikipedia.org/wiki/ANSI_escape_code

This is then interpreted by the terminal driver.

The code itself has distinct syntax. I think the reason for why it looks
like this is historical. Nicely explained e.g. here:

  https://chrisyeh96.github.io/2020/03/28/terminal-colors.html


In the future please do not be shy to post such questions to the mailing
list.

Regards,


V. Kotal
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the c-prog-lang-l mailing list