How to change text color and background in Mac terminal?

I am writing a program that should write text in different colors. I have escape code RED " \e[31m".However, if I do red on a red background, this will not work. Therefore, I also want to change the background color. I tried to use this "\e[31m\e[94mor even \e[4Xmfor text on a different background, however this does not work. Any ideas for getting red text on a white background?

This is in the format std :: cout <"COLORNAME" ....

Thank!

+4
source share
1 answer

Several SGR parameters can be connected together, but actually more compact than you tried. SGR syntax takes on the general form:

\e[ options m

options * , , , :

  • 1:
  • 30 - 37: 0 - 7 (, , , , , , , )
  • 40 - 47: 0 - 7 ( )
  • 90 - 97: 8 - 15 ( 0 - 7, "-" - -)
  • 100 - 107: 8 - 15 ( )

\e[31;47m.


(*: , .)

+4

All Articles