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:
First part: \033[display mode; foreground color; background colour m + END part: \033[0m
Note: The first part of the three parameters: Display mode, foreground color, background color is an optional parameter, you can write only one of them, in addition, because the three parameters of the different meaning of the values are unique and no duplication, so the three parameters of the writing sequence is not fixed requirements, the system can be recognized; It is recommended that you write in the default format specification.
For the end part, can also be omitted, but in order to write the specification, it is suggested \033[*** beginning, \033[0m end.
Numeric representation of the parameter meaning:
Display mode : 0 (default), 1 (highlight), 22 (not bold), 4 (underscore), 24 (non-underlined), 5 (blinking), 25 (non-flashing), 7 (inverted), 27 (non-inverting)
Foreground color : 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)
Common opening formats:
\033[0m default font normal display, not highlighted
\033[32;0m Red font Normal display
\033[1;32;40m display: Highlight font foreground color: Green background color: Black
\033[0;31;46m display mode: Normal font foreground color: Red background color: Cyan
Instance:
print "\033[1;32;40m phone number verification Code login Interface test pass!" \033[0m "
Output from Python terminal color fonts