ANSI/VT100 control sequences

来自个人维基
跳转至: 导航搜索

https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

\e” = C0 control char ESC (U+001B)

colors
color code
black 0
red 1
green 2
yellow 3
blue 4
magenta 5
cyan 6
white 7
custom color 8;5;<n>m (256-color)
8;2;<r>;<g>;<b>m (24-bit RGB)
default color 9
  • text styles
    • clear: \e[m or \e[0m
    • bold: \e[1m, dimmed: \e[2m, disable: \e[22m
    • italic: \e[3m, disable: \e[23m
    • underlined: \e[4m, double: \e[21m, disable: \e[24m
    • blinking: \e[5m, disable: \e[25m
    • inversed: \e[7m, disable: \e[27m
    • invisible: \e[8m, disable: \e[28m
    • text color: \e[3<color>m
    • background color: \e[4<color>m
    • text color but colors 0 through 7 are brighter: \e[9<color>m
    • background color but colors 0 through 7 are brighter: \e[10<color>m
  • cursor control
    • move up n lines: \e[<n>A
    • move down n lines: \e[<n>B
    • move right n lines: \e[<n>C
    • move left n lines: \e[<n>D
    • move to screen upper left corner: \e[H or \e[f
    • move to screen row v: \e[<v>H or \e[<v>f
    • move to screen row v column h: \e[<v>;<h>H or \e[<v>;<h>f
    • reset scrolling region: \e[r
    • set scrolling region to rows start through end: \e[<start>;<end>r
    • move up: \eD
    • move down: \eM
    • next line: \eE
    • save cursor position: \e7 or \e[s
    • load saved cursor position: \e8 or \e[u
  • horizontal tab stops
    • add tab at current column: \eH
    • remove tab at current column: \e[g or \e[0g
    • clear all tabs: \e[3g
  • erase text
    • from cursor to line end: \e[K or \e[0K
    • from line start to cursor: \e[1K
    • entire line: \e[2K
    • from cursor to screen end: \e[J or \e[0J
    • from screen start to cursor: \e[1J
    • entire screen: \e[2J
  • get cursor position: \e[6n
    response (fed into stdin): \e[<v>;<h>R
  • alternate screen
    • open: \e[?47h or \e[?1049h
    • close: \e[?47l or \e[?1049h