History
Almost all manufacturers of video terminals added vendor-specific escape sequences to perform operations such as placing the cursor at arbitrary positions on the screen. One example is thePlatform support
Unix-like systems
On these systems the terminal (or emulator) self-identifies using the$TERM
environment variable. A database library such as CP/M
CP/M machines varied and several competing terminals existed, like for printers, each with their own control sequences. Some early systems were headless (needing an external terminal) and personal computers with a native screen typically emulated a terminal. Application developers had to support various popular terminals and to provide an installation program to configure them. Despite the CP/M hardware abstraction layer ( BIOS), even for the same microprocessor, vendors provided platform-specific versions due to the competing disk formats, that would also be preconfigured for the native terminal (for example, various machine-specificDOS, OS/2, and Windows
MS-DOS 1.x did not support the ANSI or any other escape sequences. Only a fewAtari ST/TT/Falcon series
Atari TOS used the command system adapted from theAmigaOS
VMS / OpenVMS
VMS was designed to be controlled using Digital's text-based video terminals such as the aforementionedDescription
C0 control codes
Almost all users assume some functions of some single-byte characters. Initially defined as part of ASCII, the default C0 control code set is now defined in ISO 6429 (ECMA-48), making it part of the same standard as the C1 set invoked by the ANSI escape sequences (althoughFe Escape sequences
If the is followed by a byte in the range 0x40 to 0x5F, the escape sequence is of type . Its interpretation is delegated to the applicable C1 control code standard. Accordingly, all escape sequences corresponding to C1 control codes from ANSI X3.64 / ECMA-48 follow this format. The standard says that, in 8-bit environments, the control functions corresponding to type escape sequences (those from the set ofCSI (Control Sequence Introducer) sequences
For Control Sequence Introducer, or CSI, commands, the is followed by any number (including none) of "parameter bytes" in the range 0x30–0x3F (ASCII0–9:;<=>?
), then by any number of "intermediate bytes" in the range 0x20–0x2F (ASCII space and ), then finally by a single "final byte" in the range 0x40–0x7E (ASCII @A–Z _`a–z~
).
All common sequences just use the parameters as a series of semicolon-separated numbers such as . Missing numbers are treated as ( acts like the middle number is , and no parameters at all in acts like a reset code). Some sequences (such as CUU) treat as in order to make missing parameters useful.
A subset of arrangements was declared "private" so that terminal manufacturers could insert their own sequences without conflicting with the standard. Sequences containing the parameter bytes <=>?
or the final bytes 0x70–0x7E (p–z~
) are private.
The behavior of the terminal is undefined in the case where a CSI sequence contains any character outside of the range 0x20–0x7E. These illegal characters are either C0 control characters (the range 0–0x1F), DEL (0x7F), or bytes with the high bit set. Possible responses are to ignore the byte, to process it immediately, and furthermore whether to continue with the CSI sequence, to abort it immediately, or to ignore the rest of it.
SGR (Select Graphic Rendition) parameters
The control sequenceCSI m
, named Select Graphic Rendition (SGR), sets display attributes. Several attributes can be set in the same sequence, separated by semicolons. Each display attribute remains in effect until a following occurrence of SGR resets it. If no codes are given, is treated as (reset / normal).
Colors
= 3-bit and 4-bit
= The original specification only had 8 colors, and just gave them names. The SGR parameters 30–37 selected the foreground color, while 40–47 selected the background. Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors. Usually you could not get these as background colors, though sometimes inverse video (SGR code 7) would allow that. Examples: to get black letters on white background use , to get red use , to get bright red use . To reset colors to their defaults, use (not supported on some terminals), or reset all attributes with . Later terminals added the ability to directly specify the "bright" colors with 90–97 and 100–107. When hardware started using 8-bit= 8-bit
= As 256-color lookup tables became common on graphic cards, escape sequences were added to select from a pre-defined set of 256 colors: ESC[38;5;m Select foreground color where n is a number from the table below ESC[48;5;m Select background color 0- 7: standard colors (as in ESC [ 30–37 m) 8- 15: high intensity colors (as in ESC [ 90–97 m) 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) 232-255: grayscale from dark to light in 24 steps The ITU's T.416 Information technology - Open Document Architecture (ODA) and interchange format: Character content architectures uses ':' as separator characters instead: ESC[38:5:m Select foreground color where n is a number from the table below ESC 8:5:m Select background color There has also been a similar but incompatible 88-color encoding using the same escape sequence, seen in and . Not much is known about the scheme besides the color codes. It uses a 4×4×4 color cube.= 24-bit
= As "true color" graphic cards with 16 to 24 bits of color became common, applications began to support 24-bit colors. Terminal emulators supporting setting 24-bit foreground and background colors with escape sequences include Xterm, KDE's_=_Unix_environment_variables_relating_to_color_support_
= Before_termcap_and_terminfo_could_indicate_support_for_colors,_the_S-Lang_library_used__to_indicate_whether_a_terminal_emulator_could_use_colors_at_all_(later_reinterpreted_as_256-colors)___OSC_(Operating_System_Command)_sequences_
Most_Operating_System_Command_sequences_were_defined_by_Xterm,_but_many_are_also_supported_by_other_terminal_emulators._For_historical_reasons,_Xterm_can_end_the_command_with_Bell_character.html" ;"title="ITU.html" ;"title="38;2;;; m Select RGB foreground color ESC[ 48;2;;; m Select RGB background color The syntax is likely based on the ITU">38;2;;; m Select RGB foreground color ESC[ 48;2;;; m Select RGB background color The syntax is likely based on the ITU's T.416= Unix environment variables relating to color support
= Before termcap and terminfo could indicate support for colors, the S-Lang library used to indicate whether a terminal emulator could use colors at all (later reinterpreted as 256-colors) and whether it supports 24-bit color. This system, although poorly documented, became widespread enough for Fedora and RHEL to consider using it as a simpler and more universal detection mechanism compared to querying the now-updated libraries. However, gnome-terminal 3.14 dropped this variable as its authors considered it incorrect and no longer necessary. Some terminal emulators (urxvt, konsole) set to report the color scheme of the terminal (mainly light vs. dark background). This behavior originated in S-Lang and is used by vim. Again, gnome-terminal refuses to add this behavior, as the more "proper" xterm OSC 4/10/11 sequences already exist.OSC (Operating System Command) sequences
Most Operating System Command sequences were defined by Xterm, but many are also supported by other terminal emulators. For historical reasons, Xterm can end the command with Bell character"> as well as the standard . For example, Xterm allows the window title to be set by . A non-xterm extension is the hyperlink, from 2017, used by VTE, iTerm2, and mintty. The Linux console uses to change the palette, which, if hard-coded into an application, may hang other terminals. However, appending will be ignored by Linux and form a proper, ignorable sequence for other terminals.Fs Escape sequences
If the is followed by a byte in the range , the escape sequence is of type . This type is used for control functions individually registered with the ISO-IR registry and, consequently, available even in contexts where a different C1 control code set is used. Specifically, they correspond to single control functions approved by ISO/IEC JTC 1/SC 2 and standardized by ISO or an ISO-recognised body. Some of these are specified in ECMA-35 (ISO 2022 / ANSI X3.41), others in ECMA-48 (ISO 6429 / ANSI X3.64). ECMA-48 refers to these as "independent control functions".Fp Escape sequences
If the is followed by a byte in the range , the escape sequence is of type , which is set apart for up to sixteen private-use control functions.nF Escape sequences
If the is followed by a byte in the range , the escape sequence is of type . Said byte is followed by any number of additional bytes in this range, and then a byte in the range . These escape sequences are further subcategorised by the low four bits of the first byte, e.g. "type " for sequences where the first byte is ; and by whether the final byte is in the range indicating private use (e.g. "type ") or not (e.g. "type "). Escape sequences of this type are mostly used for ANSI/ISO code-switching mechanisms such as those used byExamples
— This clears the screen and, on some devices, locates the cursor to the y,x position 1,1 (upper left corner). — This makes text green. The green may be a dark, dull green, so you may wish to enable Bold with the sequence which would make it bright green, or combined as . Some implementations use the Bold state to make the character Bright. — This reassigns the key F10 to send to the keyboard buffer the string "DIR" and ENTER, which in the DOS command line would display the contents of the current directory. (MS-DOS ANSI.SYS only) This was sometimes used for ANSI bombs. This is a private-use code (as indicated by the letter p), using a non-standard extension to include a string-valued parameter. Following the letter of the standard would consider the sequence to end at the letter D. — This saves the cursor position. Using the sequence will restore it to the position. Say the current cursor position is 7(y) and 10(x). The sequence will save those two numbers. Now you can move to a different cursor position, such as 20(y) and 3(x), using the sequence or . Now if you use the sequence CSI u the cursor position will return to 7(y) and 10(x). Some terminals require the DEC sequences / instead which is more widely supported.In shell scripting
ANSI escape codes are often used in__In_C_
__Terminal_input_sequences_
Pressing_special_keys_on_the_keyboard,_as_well_as_outputting_many_xterm_CSI,_DCS,_or_OSC_sequences,_often_produces_a_CSI,_DCS,_or_OSC_sequence,_sent_from_the_terminal_to_the_computer_as_though_the_user_typed_it. When_typing_input_on_a_terminal_keypresses_outside_the_normal_main_alphanumeric_keyboard_area_can_be_sent_to_the_host_as_ANSI_sequences._For_keys_that_have_an_equivalent_output_function,_such_as_the_cursor_keys,_these_often_mirror_the_output_sequences._However,_for_most_keypresses_there_isn't_an_equivalent_output_sequence_to_use. There_are_several_encoding_schemes,_and_unfortunately_most_terminals_mix_sequences_from_different_schemes,_so_host_software_has_to_be_able_to_deal_with_input_sequences_using_any_scheme._ To_complicate_the_matter,_the_VT_terminals_themselves_have_two_schemes_of_input,_''normal_mode''_and_''application_mode''_that_can_be_switched_by_the_application. (draft_section)If_the_terminating_character_is_'~',_the_first_number_must_be_present_and_is_a keycode_number,_the_second_number_is_an_optional_modifier_value._If_the_terminating character_is_a_letter,_the_letter_is_the_keycode_value,_and_the_optional_number_is the_modifier_value. The_modifier_value_defaults_to_1,_and_after_subtracting_1_is_a_bitmap_of_modifier keys_being_pressed:_Meta-Ctrl-Alt-Shift._So,_for_example,_<esc>[4;2~_is Shift-End,_<esc>[20~_is_function_key_9,_<esc>[5C_is_Ctrl-Right. In_other_words,_the_modifier_is_the_sum_of_the_following_numbers:_________________________________________->_char _ _________________________________->_esc _ ____________________________________->_esc _ ___________________________________->_Alt-keypress_or_keycode_sequence _'['_ _____________________________->_Alt-[ _'['_( )_ __________________->_keycode_sequence,_ _is_a_decimal_number_and_defaults_to_1_(xterm) _'['_( )_(';' )_'~'______->_keycode_sequence,_ _and_ _are_decimal_numbers_and_default_to_1_(vt)
vt_sequences:<esc>[A_to_<esc>[D_are_the_same_as_the_ANSI_output_sequences._The_<modifier>_is_normally_omitted_if_no_modifier_keys_are_pressed,_but_most_implementations_always_emit_the_<modifier>_for_F1-F4._(draft_section) Xterm_has_a_comprehensive_documentation_page_on_the_various_function-key_and_mouse_input_sequence_schemes_from_DEC's_VT_terminals_and_various_other_terminals_it_emulates.[1~____-_Home________ [16~___-_____________ [31~___-_F17 [2~____-_Insert______ [17~___-_F6__________ [32~___-_F18 [3~____-_Delete______ [18~___-_F7__________ [33~___-_F19 [4~____-_End_________ [19~___-_F8__________ [34~___-_F20 [5~____-_PgUp________ [20~___-_F9__________ [35~___-_ [6~____-_PgDn________ [21~___-_F10_________ [7~____-_Home________ [22~___-_____________ [8~____-_End_________ [23~___-_F11_________ [9~____-_____________ [24~___-_F12_________ [10~___-_F0__________ [25~___-_F13_________ [11~___-_F1__________ [26~___-_F14_________ [12~___-_F2__________ [27~___-_____________ [13~___-_F3__________ [28~___-_F15_________ [14~___-_F4__________ [29~___-_F16_________ [15~___-_F5__________ [30~___- xterm_sequences: [A_____-_Up__________ [K_____-_____________ [U_____- [B_____-_Down________ [L_____-_____________ [V_____- [C_____-_Right_______ [M_____-_____________ [W_____- [D_____-_Left________ [N_____-_____________ [X_____- [E_____-_____________ [O_____-_____________ [Y_____- [F_____-_End_________ [1P____-_F1__________ [Z_____- [G_____-_Keypad_5____ [1Q____-_F2_______ [H_____-_Home________ [1R____-_F3_______ [I_____-_____________ [1S____-_F4_______ [J_____-_____________ [T_____-_
CSI_[_''char''
._The_CSI_sequence_should_terminate_on_the_[
.
*_Old_versions_of_Terminator_(terminal_emulator).html" "title="Bash_(Unix_shell).html" ;"title="m&\x1b[0m/i' -e 's/.*\bERR.*/\x1b[93;41m&\x1b[0m/i'
The following Bash (Unix shell)">Bash function flashes the terminal (by alternately sending reverse and normal video mode codes) until the user presses a key.
\\e[?5h \\e[?5l
This can be used to alert a programmer when a lengthy command terminates, such as with .
This will reset the console, similar to the command on modern Linux systems; however it should work even on older Linux systems and on other (non-Linux) UNIX variants.
In C
Terminal input sequences
Pressing special keys on the keyboard, as well as outputting many xterm CSI, DCS, or OSC sequences, often produces a CSI, DCS, or OSC sequence, sent from the terminal to the computer as though the user typed it. When typing input on a terminal keypresses outside the normal main alphanumeric keyboard area can be sent to the host as ANSI sequences. For keys that have an equivalent output function, such as the cursor keys, these often mirror the output sequences. However, for most keypresses there isn't an equivalent output sequence to use. There are several encoding schemes, and unfortunately most terminals mix sequences from different schemes, so host software has to be able to deal with input sequences using any scheme. To complicate the matter, the VT terminals themselves have two schemes of input, ''normal mode'' and ''application mode'' that can be switched by the application. (draft section)If the terminating character is '~', the first number must be present and is a keycode number, the second number is an optional modifier value. If the terminating character is a letter, the letter is the keycode value, and the optional number is the modifier value. The modifier value defaults to 1, and after subtracting 1 is a bitmap of modifier keys being pressed: Meta-Ctrl-Alt-Shift. So, for example, <esc>[4;2~ is Shift-End, <esc>[20~ is function key 9, <esc>[5C is Ctrl-Right. In other words, the modifier is the sum of the following numbers:-> char -> esc -> esc -> Alt-keypress or keycode sequence '[' -> Alt-[ '[' ( ) -> keycode sequence, is a decimal number and defaults to 1 (xterm) '[' ( ) (';' ) '~' -> keycode sequence, and are decimal numbers and default to 1 (vt)
vt sequences:<esc>[A to <esc>[D are the same as the ANSI output sequences. The <modifier> is normally omitted if no modifier keys are pressed, but most implementations always emit the <modifier> for F1-F4. (draft section) Xterm has a comprehensive documentation page on the various function-key and mouse input sequence schemes from DEC's VT terminals and various other terminals it emulates. Thomas Dickey has added a lot of support to it over time; he also maintains a list of default keys used by other terminal emulators for comparison. * On the Linux console, certain function keys generate sequences of the form[1~ - Home [16~ - [31~ - F17 [2~ - Insert [17~ - F6 [32~ - F18 [3~ - Delete [18~ - F7 [33~ - F19 [4~ - End [19~ - F8 [34~ - F20 [5~ - PgUp [20~ - F9 [35~ - [6~ - PgDn [21~ - F10 [7~ - Home [22~ - [8~ - End [23~ - F11 [9~ - [24~ - F12 [10~ - F0 [25~ - F13 [11~ - F1 [26~ - F14 [12~ - F2 [27~ - [13~ - F3 [28~ - F15 [14~ - F4 [29~ - F16 [15~ - F5 [30~ - xterm sequences: [A - Up [K - [U - [B - Down [L - [V - [C - Right [M - [W - [D - Left [N - [X - [E - [O - [Y - [F - End [1P - F1 [Z - [G - Keypad 5 [1Q - F2 [H - Home [1R - F3 [I - [1S - F4 [J - [T -
CSI [ ''char''
. The CSI sequence should terminate on the [
.
* Old versions of Terminator (terminal emulator)">Terminator
Terminator may refer to:
Science and technology
Genetics
* Terminator (genetics), the end of a gene for transcription
* Terminator technology, proposed methods for restricting the use of genetically modified plants by causing second generation s ...SS3 1; ''modifiers'' ''char''
when F1–F4 are pressed with modifiers. The faulty behavior was copied from CSI ''row'' ; ''column'' R
if asked for cursor position and CSI 1 ; ''modifiers'' R
if the F3 key is pressed with modifiers, which collide in the case of ''row'' 1. This can be avoided by using the ''?'' private modifier as CSI ? 6 n
, which will be reflected in the response as CSI ? ''row'' ; ''column'' R
.
* many terminals prepend ESC
to any character that is typed with the alt key down. This creates ambiguity for uppercase letters and symbols @ _
, which would form C1 codes.
* SS3 ''modifiers'' ''char''
when F1–F4 are pressed with modifiers.
See also
* ANSI art * Control character * Advanced Video Attribute Terminal Assembler and Recreator (AVATAR) * ISO/IEC JTC 1/SC 2 *Notes
References
External links