Usage:
Printf ("\ 033 [background color; font color M string \ 033 [0 m ");
Example:
Printf ("\ 033 [47; 31 mhello world \ 033 [5 m ");
Note:
47 is the background color, 31 is the font color, and hello World is the string. \ 033 [5 m is the control code
Format: Echo "\ 033 [background color; font color M string \ 033 [0 m"
Example: Echo "\ 033 [41; 36 m something here \ 033 [0 m"
The position 41 represents the background color, and the position 36 represents the color of the word.
The ASCII code is the beginning and end of the color call.
\ 033 [; M ...... \ 033 [0 m
Color Range: 40----49
40: Black
41: dark red
42: Green
43: Yellow
44: Blue
45: Purple
46: dark green
47: white
Color: 30-----------39
30: Black
31: red
32: Green
33: Yellow
34: Blue
35: Purple
36: dark green
37: white
=========== Description of the ANSI control code ==================
\ 33 [0 m close all properties
\ 33 [1 m set high brightness
\ 33 [4 m underline
\ 33 [5 m flashing
\ 33 [7 m reverse display
\ 33 [8 m blanking
\ 33 [30 m -- \ 33 [37 m sets the foreground color
\ 33 [40 m -- \ 33 [47 m set the background color
\ 33 [move the NA cursor up n rows
\ 33 [move the Nb cursor down n rows
\ 33 [move the NC cursor right n rows
\ 33 [Nd cursor shifts n rows left
\ 33 [Y; XH: Set the cursor position
\ 33 [2j clear screen
\ 33 [k clear content from cursor to end of line
\ 33 [s Save the cursor position
\ 33 [U restore cursor position
\ 33 [? 25l hide the cursor
\ 33 [? 25 h show cursor
I wrote a routine:
# Include "stdio. H"
Int main (void)
{
Int color;
For (color = 0; color & lt; 20; color ++)
{
Printf ("\ x1b [1; 4; % dmthe color of this line is % d,
% S! \ X1b [0 m \ n ", 30 + color, 30 + color," ha ha ");
}
}
Running result: