VT100-3.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. ANSI Escape Sequences
  2. Standard escape codes are prefixed with Escape:
  3. Ctrl-Key: ^[
  4. Octal: \033
  5. Unicode: \u001b
  6. Hexadecimal: \x1B
  7. Decimal: 27
  8. Followed by the command, somtimes delimited by opening square bracket ([), known as a Control Sequence Introducer (CSI), optionally followed by arguments and the command itself.
  9. Arguments are delimeted by semi colon (;).
  10. For example:
  11. \x1b[1;31m # Set style to bold, red foreground.
  12. Sequences
  13. ESC - sequence starting with ESC (\x1B)
  14. CSI - Control Sequence Introducer: sequence starting with ESC [ or CSI (\x9B)
  15. DCS - Device Control String: sequence starting with ESC P or DCS (\x90)
  16. OSC - Operating System Command: sequence starting with ESC ] or OSC (\x9D)
  17. Any whitespaces between sequences and arguments should be ignored. They are present for improved readability.
  18. General ASCII Codes
  19. Name decimal octal hex C-escape Ctrl-Key Description
  20. BEL 7 007 0x07 \a ^G Terminal bell
  21. BS 8 010 0x08 \b ^H Backspace
  22. HT 9 011 0x09 \t ^I Horizontal TAB
  23. LF 10 012 0x0A \n ^J Linefeed (newline)
  24. VT 11 013 0x0B \v ^K Vertical TAB
  25. FF 12 014 0x0C \f ^L Formfeed (also: New page NP)
  26. CR 13 015 0x0D \r ^M Carriage return
  27. ESC 27 033 0x1B \e* ^[ Escape character
  28. DEL 127 177 0x7F <none> <none> Delete character
  29. Note: Some control escape sequences, like \e for ESC, are not guaranteed to work in all languages and compilers. It is recommended to use the decimal, octal or hex representation as escape code.
  30. Note: The Ctrl-Key representation is simply associating the non-printable characters from ASCII code 1 with the printable (letter) characters from ASCII code 65 ("A"). ASCII code 1 would be ^A (Ctrl-A), while ASCII code 7 (BEL) would be ^G (Ctrl-G). This is a common representation (and input method) and historically comes from one of the VT series of terminals.
  31. Cursor Controls
  32. Hide cursor for 5 seconds
  33. echo -e "\e[?25l" ; sleep 5 ; echo -e "\e[?25h"
  34. ESC Code Sequence Description
  35. ESC[H moves cursor to home position (0, 0)
  36. ESC[{line};{column}H
  37. ESC[{line};{column}f moves cursor to line #, column #
  38. ESC[#A moves cursor up # lines
  39. ESC[#B moves cursor down # lines
  40. ESC[#C moves cursor right # columns
  41. ESC[#D moves cursor left # columns
  42. ESC[#E moves cursor to beginning of next line, # lines down
  43. ESC[#F moves cursor to beginning of previous line, # lines up
  44. ESC[#G moves cursor to column #
  45. ESC[6n request cursor position (reports as ESC[#;#R)
  46. ESC M moves cursor one line up, scrolling if needed
  47. ESC 7 save cursor position (DEC)
  48. ESC 8 restores the cursor to the last saved position (DEC)
  49. ESC[s save cursor position (SCO)
  50. ESC[u restores the cursor to the last saved position (SCO)
  51. Note: Some sequences, like saving and restoring cursors, are private sequences and are not standardized. While some terminal emulators (i.e. xterm and derived) support both SCO and DEC sequences, they are likely to have different functionality. It is therefore recommended to use DEC sequences.
  52. Erase Functions
  53. ESC Code Sequence Description
  54. ESC[J erase in display (same as ESC[0J)
  55. ESC[0J erase from cursor until end of screen
  56. ESC[1J erase from cursor to beginning of screen
  57. ESC[2J erase entire screen
  58. ESC[3J erase saved lines
  59. ESC[K erase in line (same as ESC[0K)
  60. ESC[0K erase from cursor to end of line
  61. ESC[1K erase start of line to the cursor
  62. ESC[2K erase the entire line
  63. Note: Erasing the line won't move the cursor, meaning that the cursor will stay at the last position it was at before the line was erased. You can use \r after erasing the line, to return the cursor to the start of the current line.
  64. Colors / Graphics Mode
  65. ESC Code Sequence Reset Sequence Description
  66. ESC[1;34;{...}m Set graphics modes for cell, separated by semicolon (;).
  67. ESC[0m reset all modes (styles and colors)
  68. ESC[1m ESC[22m set bold mode.
  69. ESC[2m ESC[22m set dim/faint mode.
  70. ESC[3m ESC[23m set italic mode.
  71. ESC[4m ESC[24m set underline mode.
  72. ESC[5m ESC[25m set blinking mode
  73. ESC[7m ESC[27m set inverse/reverse mode
  74. ESC[8m ESC[28m set hidden/invisible mode
  75. ESC[9m ESC[29m set strikethrough mode.
  76. Note: Some terminals may not support some of the graphic mode sequences listed above.
  77. Note: Both dim and bold modes are reset with the ESC[22m sequence. The ESC[21m sequence is a non-specified sequence for double underline mode and only work in some terminals and is reset with ESC[24m.
  78. Color codes
  79. Most terminals support 8 and 16 colors, as well as 256 (8-bit) colors. These colors are set by the user, but have commonly defined meanings.
  80. 8-16 Colors
  81. Color Name Foreground Color Code Background Color Code
  82. Black 30 40
  83. Red 31 41
  84. Green 32 42
  85. Yellow 33 43
  86. Blue 34 44
  87. Magenta 35 45
  88. Cyan 36 46
  89. White 37 47
  90. Default 39 49
  91. Reset 0 0
  92. Note: the Reset color is the reset code that resets all colors and text effects, Use Default color to reset colors only.
  93. Most terminals, apart from the basic set of 8 colors, also support the "bright" or "bold" colors. These have their own set of codes, mirroring the normal colors, but with an additional ;1 in their codes:
  94. # Set style to bold, red foreground.
  95. \x1b[1;31mHello
  96. # Set style to dimmed white foreground with red background.
  97. \x1b[2;37;41mWorld
  98. Terminals that support the aixterm specification provides bright versions of the ISO colors, without the need to use the bold modifier:
  99. Color Name Foreground Color Code Background Color Code
  100. Bright Black 90 100
  101. Bright Red 91 101
  102. Bright Green 92 102
  103. Bright Yellow 93 103
  104. Bright Blue 94 104
  105. Bright Magenta 95 105
  106. Bright Cyan 96 106
  107. Bright White 97 107
  108. 256 Colors
  109. The following escape codes tells the terminal to use the given color ID:
  110. ESC Code Sequence Description
  111. ESC[38;5;{ID}m Set foreground color.
  112. ESC[48;5;{ID}m Set background color.
  113. Where {ID} should be replaced with the color index from 0 to 255 of the following color table:
  114. 256 Color table
  115. The table starts with the original 16 colors (0-15).
  116. The proceeding 216 colors (16-231) or formed by a 3bpc RGB value offset by 16, packed into a single value.
  117. The final 24 colors (232-255) are grayscale starting from a shade slighly lighter than black, ranging up to shade slightly darker than white.
  118. Some emulators interpret these steps as linear increments (256 / 24) on all three channels, although some emulators may explicitly define these values.
  119. RGB Colors
  120. More modern terminals supports Truecolor (24-bit RGB), which allows you to set foreground and background colors using RGB.
  121. These escape sequences are usually not well documented.
  122. ESC Code Sequence Description
  123. ESC[38;2;{r};{g};{b}m Set foreground color as RGB.
  124. ESC[48;2;{r};{g};{b}m Set background color as RGB.
  125. Note that ;38 and ;48 corresponds to the 16 color sequence and is interpreted by the terminal to set the foreground and background color respectively. Where as ;2 and ;5 sets the color format.
  126. Screen Modes
  127. Set Mode
  128. ESC Code Sequence Description
  129. ESC[={value}h Changes the screen width or type to the mode specified by value.
  130. ESC[=0h 40 x 25 monochrome (text)
  131. ESC[=1h 40 x 25 color (text)
  132. ESC[=2h 80 x 25 monochrome (text)
  133. ESC[=3h 80 x 25 color (text)
  134. ESC[=4h 320 x 200 4-color (graphics)
  135. ESC[=5h 320 x 200 monochrome (graphics)
  136. ESC[=6h 640 x 200 monochrome (graphics)
  137. ESC[=7h Enables line wrapping
  138. ESC[=13h 320 x 200 color (graphics)
  139. ESC[=14h 640 x 200 color (16-color graphics)
  140. ESC[=15h 640 x 350 monochrome (2-color graphics)
  141. ESC[=16h 640 x 350 color (16-color graphics)
  142. ESC[=17h 640 x 480 monochrome (2-color graphics)
  143. ESC[=18h 640 x 480 color (16-color graphics)
  144. ESC[=19h 320 x 200 color (256-color graphics)
  145. ESC[={value}l Resets the mode by using the same values that Set Mode uses, except for 7, which disables line wrapping. The last character in this escape sequence is a lowercase L.
  146. Common Private Modes
  147. These are some examples of private modes, which are not defined by the specification, but are implemented in most terminals.
  148. ESC Code Sequence Description
  149. ESC[?25l make cursor invisible
  150. ESC[?25h make cursor visible
  151. ESC[?47l restore screen
  152. ESC[?47h save screen
  153. ESC[?1049h enables the alternative buffer
  154. ESC[?1049l disables the alternative buffer
  155. Refer to the XTerm Control Sequences for a more in-depth list of private modes defined by XTerm.
  156. Note: While these modes may be supported by the most terminals, some may not work in multiplexers like tmux.
  157. Keyboard Strings
  158. ESC[{code};{string};{...}p
  159. Redefines a keyboard key to a specified string.
  160. The parameters for this escape sequence are defined as follows:
  161. code is one or more of the values listed in the following table. These values represent keyboard keys and key combinations. When using these values in a command, you must type the semicolons shown in this table in addition to the semicolons required by the escape sequence. The codes in parentheses are not available on some keyboards. ANSI.SYS will not interpret the codes in parentheses for those keyboards unless you specify the /X switch in the DEVICE command for ANSI.SYS.
  162. string is either the ASCII code for a single character or a string contained in quotation marks. For example, both 65 and "A" can be used to represent an uppercase A.
  163. IMPORTANT: Some of the values in the following table are not valid for all computers. Check your computer's documentation for values that are different.
  164. List of keyboard strings
  165. Key Code SHIFT+code CTRL+code ALT+code
  166. F1 0;59 0;84 0;94 0;104
  167. F2 0;60 0;85 0;95 0;105
  168. F3 0;61 0;86 0;96 0;106
  169. F4 0;62 0;87 0;97 0;107
  170. F5 0;63 0;88 0;98 0;108
  171. F6 0;64 0;89 0;99 0;109
  172. F7 0;65 0;90 0;100 0;110
  173. F8 0;66 0;91 0;101 0;111
  174. F9 0;67 0;92 0;102 0;112
  175. F10 0;68 0;93 0;103 0;113
  176. F11 0;133 0;135 0;137 0;139
  177. F12 0;134 0;136 0;138 0;140
  178. HOME (num keypad) 0;71 55 0;119 --
  179. UP ARROW (num keypad) 0;72 56 (0;141) --
  180. PAGE UP (num keypad) 0;73 57 0;132 --
  181. LEFT ARROW (num keypad) 0;75 52 0;115 --
  182. RIGHT ARROW (num keypad) 0;77 54 0;116 --
  183. END (num keypad) 0;79 49 0;117 --
  184. DOWN ARROW (num keypad) 0;80 50 (0;145) --
  185. PAGE DOWN (num keypad) 0;81 51 0;118 --
  186. INSERT (num keypad) 0;82 48 (0;146) --
  187. DELETE (num keypad) 0;83 46 (0;147) --
  188. HOME (224;71) (224;71) (224;119) (224;151)
  189. UP ARROW (224;72) (224;72) (224;141) (224;152)
  190. PAGE UP (224;73) (224;73) (224;132) (224;153)
  191. LEFT ARROW (224;75) (224;75) (224;115) (224;155)
  192. RIGHT ARROW (224;77) (224;77) (224;116) (224;157)
  193. END (224;79) (224;79) (224;117) (224;159)
  194. DOWN ARROW (224;80) (224;80) (224;145) (224;154)
  195. PAGE DOWN (224;81) (224;81) (224;118) (224;161)
  196. INSERT (224;82) (224;82) (224;146) (224;162)
  197. DELETE (224;83) (224;83) (224;147) (224;163)
  198. PRINT SCREEN -- -- 0;114 --
  199. PAUSE/BREAK -- -- 0;0 --
  200. BACKSPACE 8 8 127 (0)
  201. ENTER 13 -- 10 (0
  202. TAB 9 0;15 (0;148) (0;165)
  203. NULL 0;3 -- -- --
  204. A 97 65 1 0;30
  205. B 98 66 2 0;48
  206. C 99 66 3 0;46
  207. D 100 68 4 0;32
  208. E 101 69 5 0;18
  209. F 102 70 6 0;33
  210. G 103 71 7 0;34
  211. H 104 72 8 0;35
  212. I 105 73 9 0;23
  213. J 106 74 10 0;36
  214. K 107 75 11 0;37
  215. L 108 76 12 0;38
  216. M 109 77 13 0;50
  217. N 110 78 14 0;49
  218. O 111 79 15 0;24
  219. P 112 80 16 0;25
  220. Q 113 81 17 0;16
  221. R 114 82 18 0;19
  222. S 115 83 19 0;31
  223. T 116 84 20 0;20
  224. U 117 85 21 0;22
  225. V 118 86 22 0;47
  226. W 119 87 23 0;17
  227. X 120 88 24 0;45
  228. Y 121 89 25 0;21
  229. Z 122 90 26 0;44
  230. 1 49 33 -- 0;120
  231. 2 50 64 0 0;121
  232. 3 51 35 -- 0;122
  233. 4 52 36 -- 0;123
  234. 5 53 37 -- 0;124
  235. 6 54 94 30 0;125
  236. 7 55 38 -- 0;126
  237. 8 56 42 -- 0;126
  238. 9 57 40 -- 0;127
  239. 0 48 41 -- 0;129
  240. - 45 95 31 0;130
  241. = 61 43 --- 0;131
  242. [ 91 123 27 0;26
  243. ] 93 125 29 0;27
  244. 92 124 28 0;43
  245. ; 59 58 -- 0;39
  246. ' 39 34 -- 0;40
  247. , 44 60 -- 0;51
  248. . 46 62 -- 0;52
  249. / 47 63 -- 0;53
  250. ` 96 126 -- (0;41)
  251. ENTER (keypad) 13 -- 10 (0;166)
  252. / (keypad) 47 47 (0;142) (0;74)
  253. * (keypad) 42 (0;144) (0;78) --
  254. - (keypad) 45 45 (0;149) (0;164)
  255. + (keypad) 43 43 (0;150) (0;55)
  256. 5 (keypad) (0;76) 53 (0;143) --
  257. Resources
  258. Wikipedia: ANSI escape code
  259. Build your own Command Line with ANSI escape codes
  260. ascii-table: ANSI Escape sequences
  261. bluesock: ansi codes
  262. bash-hackers: Terminal Codes (ANSI/VT100) introduction
  263. XTerm Control Sequences
  264. VT100 – Various terminal manuals
  265. xterm.js – Supported Terminal Sequences
  266. click to expand⣿⣿⣷⣶⣦⣤⣄⣀⡀ Control Characters - VT100 User Guide
  267. 【𝐄𝐍𝐃】