I need to be able to be able to make some text on terminal more noticeable, and what I thought was to make the text colored. Either the actual text, or the space in each letter’s rectangle-thingy (think vi’s cursor). The only two extra specs that I think are important for my application are : the program should be distro-independent (a certainty is that the code will only be run under BASH), and it shouldn’t output extra characters when writing to a file (either from the actual code, or when piping the output)
I searched the web for some info, but I could only find info for the deprecated cstdlib (stdlib.h), and I need (actually, it’s more of a “want”) to do it using the functionality of iostream.
Most terminals respect the ASCII color sequences. They work by outputting
ESC, followed by[, then a semicolon-separated list of color values, thenm. These are common values:So outputting
"\033[31;47m"should make the terminal front (text) color red and the background color white.You can wrap it nicely in a C++ form: