📜 ⬆️ ⬇️

Console Output Color

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
0normal mode
onefatty
fourunderlined
fiveflashing
7inverted colors
eightinvisible
text color
thirtythe black
31red
32green
33yellow
34blue
35purple
36blue
37white
background color
40the black
41red
42green
43yellow
44blue
45purple
46blue
47white


Now a few examples. All this can be tested by entering the echo -e " " in the echo -e " " console window.

InputResult
\ x1b [31m Test \ x1b [0mimage
\ x1b [37; 43m Test \ x1b [0mimage
\ x1b [4; 35m Test \ x1b [0mimage

')
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
image

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.

Source: https://habr.com/ru/post/94647/


All Articles