ANSI

ANSI

ANSI escape sequences
ANSI escape sequences are a standard for in-band-signaling
to control cursor location,color,font styling, and other options on video text terminal and terminal
emulators
.

C0 control codes

Fe Escape code

if the ESC is followed by a byte in the range 0x40 to 0x5f,the escape sequences is ot type Fe.

some type Fe ANSI escape sequences
Code C1 Abbr Name Effect
ESC [ 0x9B CSI Control sequences Introducer

ANSI control sequences

some ANSI control sequences
Code Abbr Name Effect
CSI n m SGR Select Graphic Rendition Sets colors and style of the characters following this code

SGR(Select Graphic Rendition) parameters

The control sequences CSI n m,named Select Graphic
Rendition(SGR),
sets display attribute.

n Name Note
0 Reset or normal All attributes off
1 Bold or increased intensity
2 Faint,decreased intensity,or dim May be implemented as a light font weight like bold
3 Italic
4 underline
30-37 set foreground color
40-47 set background color
90-97 set bright foreground color
100-107 set bright background color

colors

Several attributes can be set in the same sequences,separated by the semicolons(;).
Each display attributes remains in effect util the following occurrence of SGR resets it.
If no codes are give,CSI m is treated as CSI 0m(reset/normal)

Examples:

1
2
3
`ESC[0m`:reset all attributes
`ESC[31m`:to get red letters
`ESC[1;30;47m`:to get bold(bright) black letters on white background color
FG BG Name
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Magenta
36 46 Cyan
37 47 White

\033 represents ESC in ASCII code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#define ASNI_FG_BLACK   "\33[1;30m"
#define ASNI_FG_RED "\33[1;31m"
#define ASNI_FG_GREEN "\33[1;32m"
#define ASNI_FG_YELLOW "\33[1;33m"
#define ASNI_FG_BLUE "\33[1;34m"
#define ASNI_FG_MAGENTA "\33[1;35m"
#define ASNI_FG_CYAN "\33[1;36m"
#define ASNI_FG_WHITE "\33[1;37m"
#define ASNI_BG_BLACK "\33[1;40m"
#define ASNI_BG_RED "\33[1;41m"
#define ASNI_BG_GREEN "\33[1;42m"
#define ASNI_BG_YELLOW "\33[1;43m"
#define ASNI_BG_BLUE "\33[1;44m"
#define ASNI_BG_MAGENTA "\33[1;35m"
#define ASNI_BG_CYAN "\33[1;46m"
#define ASNI_BG_WHITE "\33[1;47m"
#define ASNI_NONE "\33[0m"

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022-2023 Ataraxia

请我喝杯咖啡吧~