Introduction to ANSI control codes
ANSI control code is used to control cursor movement and character color in the character display system. It is often used in BBS systems.
Ansi escape sequences, also known as VT100 series control codes, are translated as ANSI control codes in China. As the name suggests, you need to support the VT100 series of terminals. Of course, it is no longer limited to VT100, including xterm and linux.
The START flag of the ANSI control code is ESC [. ESC corresponds to 033 (octal) of the ASCII code table. The linux Command echo uses-e to enable escape and \ 033 to input ESC, \ 033 [31m is ESC [31 m.
Format
Echo:-e is used to enable escape in echo. \ e or \ 033 is used to output the Esc symbol.
Format: echo-e "\ 033 [background color; font color m string \ 033 [0 m"
Note that m follows the string.
For example:
Echo-e "\ 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
**************************************** *************
\ 033 [0 m close all attributes
\ 033 [1 m set high brightness
\ 03 [4 m underline
\ 033 [5 m flashing
\ 033 [7 m reverse display
\ 033 [8 m blanking
\ 033 [30 m -- \ 033 [37 m set the foreground color
\ 033 [40 m -- \ 033 [47 m set the background color
\ 033 [move the nA cursor up n rows
\ 03 [move the nB cursor down n rows
\ 033 [the nC cursor shifts n rows right
\ 033 [nD cursor shifts n rows left
\ 033 [y; xH: Set the cursor position
\ 033 [2J clear screen
\ 033 [K clear content from cursor to end of line
\ 033 [s Save the cursor position
\ 033 [u restore cursor position
\ 033 [? 25l hide the cursor
\ 33 [? 25 h show cursor
**************************************** *************
Color Range: 40---49
40: Black
41: dark red
42: Green
43: Yellow
44: Blue
45: Purple
46: dark green
47: white
Color Range: 30---39
30: Black
31: red
32: Green
33: Yellow
34: Blue
35: Purple
36: dark green
37: white
**************************************** *************
Display character Property Control
[N1; n2;... m
I. Set the attribute status of the display character;
II. If there are more than two attribute states to be set, separate the code (n1; n2;...) with a semicolon;
Iii. Unless reset, the original property is retained;
**************************************** *************
Purpose
ANSI control code relies on terminals rather than languages, so there is no problem with applications in shell, perl, and c;
I'm afraid I have to imagine what the ANSI control code can do, such as dressing up terminals and using color warnings or classification.
Example
Color and code table
Code:
#! /Bin/bash
#
For (I = 40; I <47; I ++ ))
{
For (j = 30; j <37; j ++ ))
{
# Echo $ I, $ j
Echo-en "\ 033 [" $ I ";" $ j "m" $ I ";" $ j "m \ 033 [0 m"
}
Echo ""
}
As mentioned above, the color range of the background and font is 40-49 and 30-39, but it seems that there is no difference between 38 and 39, 48 and 49 (not because of my weak color ...), adjust the range of I and j to obtain:
Code:
#! /Bin/bash
#
For (I = 40; I <50; I ++ ))
{
For (j = 30; j <40; j ++ ))
{
# Echo $ I, $ j
Echo-en "\ 033 [" $ I ";" $ j "m" $ I ";" $ j "m \ 033 [0 m"
}
Echo ""
}
Other font attributes:
BTW:
The control of the optical indicator has not been applied yet.