Simple Linux terminal beautification method sharing

Time:2021-4-3

Green font output:

Copy code

The code is as follows:

echo -e “\033[1;32;40mPass\033[0m”

 
Red font output:

Copy code

The code is as follows:

echo -e “\033[1;31;40mFail\033[0m”


The color of text terminal can be generated by using “ANSI unconventional character sequence”. give an example:
 

Copy code

The code is as follows:

  echo -e “\033[44;37;5m ME \033[0m COOL”

The functions of the above command settings are as follows: the background color is blue, the foreground color is white, the font flashes, and the output character “me”, and then reset the screen to the default setting, and the output character “cool”. “E” is an option of the command echo, which is used to activate the parser of special characters. “\ 033” guides unconventional character sequences. “M” means to set the attribute and then end the unconventional character sequence. In this case, the real valid characters are “44; 37; 5” and “0”. Different color combinations can be generated by modifying “44; 37; 5”. The numerical value has nothing to do with the sequence of coding.
 
The parameters you can choose are as follows:
Color code:
QUOTE:
Word background color range: 40 — 49 word color: 30 — 39
 
40: Black 30: Black
41: Red 31: Red
42: Green 32: Green
43: Yellow 33: yellow
44: Blue 34: Blue
45: Purple 35: Purple
46: dark green 36: dark green
47: white 37: white
 
ANSI control code:
QUOTE:
\033 [0m] close all attributes
\033 [1m set high brightness
\03 [4m]
\033 [5m]
\033 [7m reverse display
\033 [8m] blanking
\033 [30m — [033 [37m] set foreground color
\033 [40m — [033 [47m] setting background color
\033 [Na] move the cursor up n lines
\03 [NB] move the cursor down n lines
\033 [NC] the cursor moves n lines to the right
\033 [nd] the cursor moves n lines to the left
\033 [y; XH] set cursor position
\033 [2J clear screen
\033 [k] clear the contents from the cursor to the end of the line
\033 [S] save cursor position
\033 [u restore cursor position
\033 [? 25L hide cursor
\33 [? 25h display cursor

Specific excerpts are as follows:
\033 [0m] close all attributes
\033 [1m set high brightness
\033 [4m]
\033 [5m]
\033 [7m reverse display
\033 [8m] blanking
\033 [30m — [033 [37m] set foreground color
\033 [40m — [033 [47m] setting background color
\033 [Na] move the cursor up n lines
\033 [NB] move the cursor down n lines
\033 [NC] the cursor moves n lines to the right
\033 [nd] the cursor moves n lines to the left
\033 [y; XH] set cursor position
\033 [2J clear screen
\033 [k] clear the contents from the cursor to the end of the line
\033 [S] save cursor position
\033 [u restore cursor position
\033 [? 25L hide cursor
\033 [? 25h display cursor
 
[< parameters > m set display properties. The same sequence can set one or more properties
Par action
0 reset all properties to default values
1 set border www.jb51.net  
2 set brightness to half (simulate one color to another)
4 set shading (simulate one color to another)
(the color used for simulation is set by using ESC].)
5 setting flashing
7 setting reverse video
10 reset the selected image and display the control mark,
Invert element tags
11 select the empty image and set the display control flag,
Reset reverse flag
12 select the empty image, set the display control flag,
Reset the invert flag. (after completing the image table conversion
Reversing the flag before changing causes the error of each byte
High inversion.)
21 set normal brightness (not compatible with ecma-48)
22 set normal brightness
24 turn off underline
25 does not flash
27 reverse video off
30 black foreground
31 red foreground
32 green prospects
33 Brown foreground
34 blue foreground
35 magenta prospects
36 peacock blue prospects
37 white foreground
Turn on the underline and set the default foreground color
39 turn off underline and set the default foreground color
40 black background
41 red background
42 green background
43 brown background
44 blue background
45 magenta background
46 peacock blue background
47 white background
49 set default background color

Recommended Today

Deeply analyze the principle and practice of RSA key

1、 Preface After experiencing many dark moments in life, when you read this article, you will regret and even be angry: why didn’t you write this article earlier?! Your darkest moments include: 1. Your project needs to be connected with the bank, and the other party needs you to provide an encryption certificate. You have […]