ANSI/ECMA Terminal Output Sequences =================================== ANSI terminal sequences are followed by one or more characters. What are most commonly called ANSI escape sequences are ANSI-X3.41/ANSI-X3.64/ECMA-48 control sequences. They are sometimes also called VT terminal sequences as the DEC VT series of terminals were some of the earliest to implement them, starting with the VT50. Sequences are split into three general groups: {&00-&3F} ie to ? - digits and punctuation {&40-&5F} ie @ to _ - upper case letters {&60-&7F} ie ` to ~ - lower case letters ANSI-X3.41 Upper-Case Terminal Escape Sequences ----------------------------------------------- These are VT52 sequences, VT100 and later interpret them differently @ A Cursor up Move cursor one line upwards, halts on top line. B Cursor down Move cursor one line downwards, halts on bottom line. C Cursor right Move cursor one column to the right, halts at right edge. D Cursor left Move cursor one column to the left, halts at left edge. E Clear screen Clear screen and place cursor at top left corner. F G H Cursor home Move cursor to the upper left corner. I Cursor up and insert Move cursor one line upwards and scroll if top line. J Clear to end of screen Clear screen from cursor onwards. K Clear to end of line Clear line from cursor onwards. L Insert line Insert a line. M Delete line Remove line. N O P Q R S T U V W X Y<32+y><32+x> Set cursor position counting from (0,0). Z [ Control Sequence Introducer - starts ANSI-X3-64/EMCA-48 control sequence. \ ] ^ _ ANSI-X3.64/ECMA-48 CSI Terminal Control Sequences ------------------------------------------------- ANSI CSI terminal control sequences are [ followed by between zero and 16 8-bit numeric parameters, separated by ; and terminated with a letter, where is CHR$27, eg "[3;4H" or "[2;33;45m". Omitted parameters default to 0. Where 0 would do nothing it is taken as 1, for example "[A", "[0A", and "[1A" all move up 1 character position. A control sequence can start with a character '<', '=', '>' or '?' before the parameters, for instance "[=3h". These are private sequences specific to the output device. For instance, "[?..." are private VT sequences. * commonly supported - less commonly supported [@ - Insert spaces, characters pushed to the right [A * Move cursor up places [B * Move cursor down places [C * Move cursor right places [D * Move cursor left places [E * Move cursor to start of line lines down [F * Move cursor to start of line lines up [G * Move cursor to ,, counting from 1 [;H * Move cursor to (,), counting from (1,1) [I Move cursor right tabs [J * Clear display: 0=cursor to end 1=start to cursor 2=whole screen Cursor position afterwards is undefined, host should send new cursor position. [2J[H should do a conventional 'CLS'. [K * Clear in line: 0=cursor to end 1=start to cursor 2=whole line Cursor position unchanged. [L - Insert lines at cursor, pushing lines down [M - Delete lines at cursor, pulling lines up [N Erase in field [O Erase in qualified field [P - Delete characters on current line [Q Set editing mode extent [R * Report cursor position as [;R, counting from (1,1) [S * Scroll up lines [T * Scroll down lines [U - Next page, is pages to jump forward [V - Previous page, is pages to jump back [W Set/Clear tabs [X - Erase characters on current line [Y Move cursor to next tab [Z Move cursor to previous tab [...[ Reserved Start reversed string [...\ Reserved Parallel text [...] - Private control sequence Start directed string [...^ Reserved Select movement direction [..._ Reserved [` - Move cursor to , characters or pixels [a - Move cursor right characters or pixels [b Repeat previous character times [c - Query device, returns [...c [d - Move cursor to , character or pixel position [e - Move cursor down characters or pixels [;f - Move cursor to (,) character or pixel [g - Clear tabs, 0=clear horizontal tab at current position 1=clear vertical tab at current position 2=clear all hozisontal tabs on current line 3=clear all tabs [h - Set display mode, varies by device [i - AUX port/printer control, varies by device, common are: 0=print screen 1=print current line 2=send to host, 4=reset printer 5=set printer 6=start printer 7=stop printer [...j Reserved Character position backward [...k Reserved Line position backward [l - Reset display mode, reverses [h setting [...m * Set attributes and colours, defaults to 0 [n - Device status, reports [h setting 5=reports status as [n 0=ok, 1=busy, 2=busy, 3=failure 6=reports cursor position as [;R, counting from 1 [o Define area [;"string"p - Set keyboard strings [q - Set LEDs, Disable/Enable X support 0=all off 1=ScrollLock 2=NumLock 3=CapsLock 20+n=LED off [;r - Set scrolling region between row and row , counting from 1 [s * Save cursor position [t * Do stuff with windows [u * Restore ("unsave") cursor position [v [w [x [y [z [{ [| [} [~ ANSI colour codes for [...m -------------------------------- 0+n * turn attribute on 10+n * select font 20+n * turn attribute off 30+n * foreground colour 40+n * background colour 90+n - bright foreground colour 100+n - bright background colour Attributes 0 reset all attributes and colours 20 1 bold on 21 bold off (*note) 2 faint on 22 faint off 3 italics on 23 italics off 4 underline on 24 underline off 5 blink on (slow) 25 blink off 6 blink on (rapid) 26 blink off 7 inverse on 27 inverse off 8 conceal on 28 conceal off 9 strikethrough on 29 strikethrough off Colours 30 black foreground 40 black background 31 red foreground 41 red background 32 green foreground 42 green background 33 yellow foreground 43 yellow background 34 blue foreground 44 blue background 35 magenta foreground 45 magenta background 36 cyan foreground 46 cyan background 37 white foreground 47 white background 38 extended foreground colour 48 extended background colour 39 default foreground 49 default background 90 bright black foreground 100 bright black background 91 bright red foreground 101 bright red background 92 bright green foreground 102 bright green background 93 bright yellow foreground 103 bright yellow background 94 bright blue foreground 104 bright blue background 95 bright magenta foreground 105 bright magenta background 96 bright cyan foreground 106 bright cyan background 97 bright white foreground 107 bright white background On systems with Bright selectable, [1m usually only sets bright foreground. Bright background is typically only selectable with controls 100-107. On many systems [21m does not turn off Bright as expected, but often turns on double-underline. This means that the only universal method to turn Bright off is to turn off all effects and reset colours with [0m. On systems with Bright selectable "Dim White" and "Bright Black" are types of grey, and "Bright Black" is sometimes the same as "Dim Black". The greyscale colours should be: 30:Black 30;1/90:Dim Gray 37:Bright Grey 37;1/97:White 40:Black 100:Dim Gray 47:Bright Grey 107:White or 30:Black 30;1/90:Black 37:Bright Grey 37;1/97:White 40:Black 100:Black 47:Bright Grey 107:White From experimentation I've found it best to set bright foreground colours by emitting control 30+n and the bright control, and to set bright background colours by emitting control 40+n and control 100+n. For example: [34;1m - set bright blue foreground [41;101m - set bright red background Extended colours 38/48;2;;; to select RGB colour components 0-255 38/48;5; to select colour - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Other Output Sequences ====================== Private VT Terminal Output Sequences ------------------------------------ [?h - Set terminal setting [?3h - Set to 132 columns [?l - Reset terminal setting [?3l - Set to 80 columns [?n - Report setting [?3n - Report number of columns ANSI-X3.64/ECMA-48 Intermediate Control Sequences ================================================= These have a space character before the terminating letter, ie 1B 5B ... 20 . [@ scroll left [A scroll right [;B graphic size modification [C graphic size selection [;D font selection [E thin space specification [F justify [;G spacing increment [G quad [I select size unit [J page format [K select character spacing [L select line spacing [M identify graphic subrepertoire [N [O identify device [P page position absolute [Q page position forward [R page position backward [;S select presentation directions [;T dimension text area [U set line home [V set line limit [W function key [X select print quality [;Y sheet eject and feed [Z presentation expand or contract [[ set space width [\ set additional character separation [] select alternative presention [^ selective tabulation [_ graphic character combination [` tabulation aligned trailing edge [a tabulation aligned leading edge [b tabulation aligned centred [c tabulation centred on character [d tabulation stop remove [e select character orientation [f set reduced character separation [g set character spacing [h set line spacing [i set page home [j set page limit [;k select character path [l [m [n [o ANSI-X3.64/ECMA-48 (previous ECMA-6) esc 40 @ esc 41 A esc 42 B break permitted esc 43 C no break here esc 44 D esc 45 E next line esc 46 F start of selected area esc 47 G end of selected area esc 48 H set character tab esc 49 I character tab with justify esc 4A J line tabulation set esc 4B K partial line forward esc 4C L partial line backward esc 4D M reverse line feed esc 4E N single-sift two esc 4F O single-shift three esc 50 P device control string esc 51 Q private use one esc 52 R private use two esc 53 S set transmit state esc 54 T cancel esc 55 U message waiting esc 56 V start of guarded area esc 57 W end of guarded area esc 58 X start of string esc 59 Y esc 5A Z single character introducer esc 5B [ control sequnce intro - [ esc 5C \ string terminator esc 5D ] operating system command esc 5E ^ privacy message esc 5F _ command esc 60 ` disable manual input esc 61 a interrupt esc 62 b enable manual input esc 63 c reset to initial state esc 64 d command delimiter esc 65 e ... esc 6D m esc 6E n locking shift two esc 6F o locking shift three esc 7C | locking shift three right esc 7D } locking shift two right esc 7E ~ locking shift one right X3-41 X X3-64 [... Escape sequence: or Control sequence: [... VT-52 sequences =============== Code Name Meaning BEL Bell System bell. BS Backspace Delete character to left of cursor. HT Tabulator Horizontal tabulator. FF Formfeed Form feed. VT Tabulator Vertical tabulator LF Line feed Line feed. CR Carriage Return Move cursor to the start of the line. ESC = VT420: Keypad generates sequences ESC > VT420: Keypad generates digits ESC < VT420: Enter ANSI mode ESC ^ VT420: Enter auto print mode ESC _ VT420: Exit auto print mode ESC A Cursor up Move cursor one line upwards. ESC B Cursor down Move cursor one line downwards. ESC C Cursor right Move cursor one column to the right. ESC D Cursor left Move cursor one column to the left. ESC E Clear screen Clear screen and place cursor at top left corner. ESC F Enter graphics mode ESC G Exit graphics mode ESC H Cursor home Move cursor to the upper left corner. ESC I Cursor up and insert Move cursor one line upwards and scroll. ESC J Clear to end of screen Clear screen from cursor onwards. ESC K Clear to end of line Clear line from cursor onwards. ESC L Insert line Insert a line. ESC M Delete line Remove line. ... ESC V Print cursor line ESC W Enter printer controller mode ESC X Exit printer controller mode ESC Y Set cursor position Position cursor. ESC Z Identify ESC ] Print screen ESC b Foreground color Set text colour. ESC c Background color Set background colour. ESC d Clear to start of screen Clear screen up to cursor. ESC e Cur_on Show cursor. ESC f Cur_off Hide cursor. Blink_on Switch on cursor blinking. Blink_off Switch off cursor blinking. Set_blink Set blink rate. Get_blink Inquire blink rate. ESC g ESC h ESC i ESC j Save cursor position "Remember" cursor. ESC k Restore cursor position Restore cursor. ESC l Clear line Clear current line. ESC m ESC n ESC o Clear to start of line Clear current line up to cursor. ESC p Reverse video Switch on inverse video text. ESC q Normal video Switch off inverse video text. ... ESC v Wrap on Enable line wrap. ESC w Wrap off Disable line wrap. Display modes for [=h ------------------------------- 0 40 x 25 text, ANSI colours, greyscale 1 40 x 25 text, ANSI colours 2 80 x 25 text, ANSI colours, greyscale 3 80 x 25 text, ANSI colours 4 320 x 200 graphics, 4 colours, greyscale 5 320 x 200 graphics, 4 colours 6 640 x 200 graphics, 2 colours 7 Enable line wrapping 13 320 x 200 graphics, 16 colours 14 640 x 200 graphics, 16 colours 15 640 x 350 graphics, 2 colours 16 640 x 350 graphics, 16 colours 17 640 x 480 graphics, 2 colours 18 640 x 480 graphics, 16 colours 19 320 x 200 graphics, 256 colours Display settings for [h --------------------------------- 4 [4h - Insert characters, [4l - Overwrite characters 7 [7h - Enable line wrapping, [7l - disable line wrapping 12 [12h - Local echo off, [12l - Local echo on 20 [20h - Set NL, [20l - Reset LF Also seen: Display modes ------------- 0 40 x 25 monochrome (text) 1 40 x 25 color (text) 2 80 x 25 monochrome (text) 3 80 x 25 color (text) 4 320 x 200 4-color (graphics) 5 320 x 200 monochrome (graphics) 6 640 x 200 monochrome (graphics) 7 Enables line wrapping 13 320 x 200 color (graphics) 14 640 x 200 color (16-color graphics) 15 640 x 350 monochrome (2-color graphics) 16 640 x 350 color (16-color graphics) 17 640 x 480 monochrome (2-color graphics) 18 640 x 480 color (16-color graphics) 19 320 x 200 color (256-color graphics)