How Python terminals output color fonts
Implementation process:
The character color of terminal is controlled by escape sequence, and it is the system display function in text mode, which is independent of the specific language.
The escape sequence begins with the ESC, which is done with \033 (the ASCII code for ESC is 27 in decimal notation, or 033 in octal)
Writing format:
\033[display mode, foreground color, background m+ string \033[0m
Note :
display mode, foreground color, background color are optional parameters;
The foreground is the color of the font;
M is a must-write parameter;
Three parameters are not ordered, try to write in the following format
Example : print ("\033[33;41m Hello It Network \033[0m")
The meaning of the three parameters:
Display mode
0 (default), 1 (highlighted), 22 (not bold), 4 (underscore), 24 (non-underlined), 5 (blinking), 25 (non-blinking), 7 (inverted), 27 (non-inverting)
Front view
30 (Black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (magenta), 36 (cyan), 37 (white)
Background color
40 (Black), 41 (red), 42 (green), 43 (yellow), 44 (blue), 45 (magenta), 46 (cyan), 47 (white)
To illustrate:
Display by default, yellow font, red background
Print ("\033[0;33;41m Hello It Network \033[0m")
Display mode highlight, green font, red background
Print ("\033[1;32;41m Hello It Network \033[0m")
Font display RED
Print ("\033[31m Hello It Network \033[0m")
This article is from the "506554897" blog, please be sure to keep this source http://506554897.blog.51cto.com/2823970/1932861
How Python terminals output color fonts