Briefly about how to make color output of text for your console program or script, as well as to supplement it with other design elements. Actually, you can assign text color, background color below it, make the text bold, underlined, invisible and even blinking.
The pattern for use in modern command shells and programming languages is:
\ x1b [ ...
m . This is an ESCAPE sequence, where
\ x1b denotes an ESC character (decimal ASCII code 27), and instead of "..." values from the table below are substituted, and they can be combined, then you need to list them separated by a semicolon.
attributes |
0 | normal mode |
one | fatty |
four | underlined |
five | flashing |
7 | inverted colors |
eight | invisible |
text color |
thirty | the black |
31 | red |
32 | green |
33 | yellow |
34 | blue |
35 | purple |
36 | blue |
37 | white |
background color |
40 | the black |
41 | red |
42 | green |
43 | yellow |
44 | blue |
45 | purple |
46 | blue |
47 | white |
Now a few examples. All this can be tested by entering the
echo -e " "
in the
echo -e " "
console window.
Input | Result |
\ x1b [31m Test \ x1b [0m |  |
\ x1b [37; 43m Test \ x1b [0m |  |
\ x1b [4; 35m Test \ x1b [0m |  |
')
Note that in all three cases, after the word Test, there is a sequence
\ x1b [0m , which simply resets the style to the standard one.
Comprehensive use case:
\ x1b [1; 31m String \ x1b [0m with \ x1b [4; 35; 42m different \ x1b [0m \ x1b [34; 45m styles \ x1b [0m \ x1b [1; 33m clearance \ x1b [0m |  |
Good coloring of the output often greatly facilitates the perception of information. So try and experiment.
PS Also about this and some other can be read in
man console_codes
. Thanks
Riateche for the hint.