C language | | How to output colored words in c language

How to output colorful characters in c language


Use format: style start + modified string + style end

Start of style:

  • \033[+Parameter 1+: +Parameter 2+: +Parameter 3+m

Parameter 1: Representative background color

Optional values ​​and meaning:

Word background color range: 40-49 
40: black 
41: deep red 
42: green 
43: yellow 
44: blue 
45: purple 
46: dark green 
47: white

 

Parameter 2: Representative font color

Optional values ​​and meaning:

Word color: 30-39 
30: black 
31: red 
32: green 
33: yellow 
34: blue 
35: purple 
36: dark green 
37: white 
38: set an underline on the default foreground color 
39: after the default Turn off underline on set color

 

Parameter 3: Represents the display effect [When parameter 1 (background color) is not needed, it can also be placed in the position of parameter 1]

Let's take a look at the description of ANSI control codes

\33[0m close all properties 
\33[1m set high brightness 
\33[2m low brightness (decreased) display 
\33[4m underline 
\33[5m flashing 
\33[7m reverse display 
\33[8m blanking 
\33[30m - \33[37m Set the foreground color 
\33[40m - \33[47m Set the background color 
\33[nA Move the cursor up n lines 
\33[nB Move the cursor down n lines 
\33[nC Move the cursor right n lines 
\ 33[nD Move the cursor to the left by n lines 
\33[y;xH Set the cursor position 
\33[2J Clear the screen 
\33[K Clear the content from the cursor to the end of the line 
\33[s Save the cursor position 
\33[u Restore the cursor position 
\ 33[?25l hide the cursor 
\33[?25h show the cursor

 

End of style

  • \033[0m

 

important point:

  • After using the effect, you must add \033[0m to end the effect, otherwise it will affect the subsequent use

  • If you do not use the following parameters, you do not need to add

  • After testing \007 can only take effect once

Example:

printf("\007 beep!\033[0m\n") //make a sound, test the effect under wimdows, and test the effect under linux

 

Guess you like

Origin blog.csdn.net/qq_40399012/article/details/84195092