Expand description
Module with ansi escape codes.
There are several types of codes here:
- Sequences: string/char used to introduce escape sequence, most of the other codes use them
- General ascii codes: single char sequences some of them have escape codes in rust string/char literals (such as ‘\n’)
- Macro codes: these escape codes have one or more parameters. Here
they are in form of a macro that takes the parameters. If the macro is
invoked with literals, it expands to
&'static str. If the arguments are not literals it expands to a call to theformat!macro. Because these codes may expand either to&'static strorStringyou can use theGetString::get_stringmethod to getString, or you can useAsRef<str>::as_refmethod to get&str, or you can useInto<Cow<'static, str>>::intoto get the possibly owned string. - String codes: these codes are just strings that can be just printed to terminal to do what they say they do. This is the majority of the codes.
- Function codes: These codes have too complicated input to be used in a macro.
§Sources
Terminal escape codes go back to terminals in 1970. The basic codes are taken from here. Some other codes are shown at wikipedia. Xterm has also good documentation on many codes here. Codes are also documented in terminal documentation here.
Modern terminals add their own extensions to the old codes. The new codes are in the terminal documentation. Many terminals support codes added by kitty.
Macros§
- bg
- Creates a true rgb background color. R, G and B must be values in range 0..256.
- bg256
- Creates a background color, color is value in range 0..256.
- column
- Moves cursor to the given column.
- delete_
chars - Delete n characters, moving the chars from right.
- delete_
columns - Delete n columns, moving them from the right.
- delete_
lines - Delete n lines at the cursor, moving the remaining from bottom.
- fg
- Creates a true rgb foreground color. R, G and B must be values in range 0..256.
- fg256
- Creates a foreground color, color is value in range 0..256.
- insert_
chars - Insert n characters, moving them to the right.
- insert_
columns - Insert n columns, moving them to the right.
- insert_
lines - Insert n lines at the cursor moving them down.
- move_
down - Moves cursor down by N positions.
- move_
left - Moves cursor left by N positions.
- move_
right - Moves cursor right by N positions.
- move_to
- Moves cursor to the given position. Position of the top left conrner is (1, 1).
- move_up
- Moves cursor up by N positions.
- repeat_
char - Repeat the previous char n times.
- request_
color_ code - Requests the current color assigned to the given color code.
- reset_
color_ code - Resets the color definition for the given color code.
- scroll_
region - set the scroll region in the terminal. also moves the cursor to the top left.
- set_
down - Moves cursor to the start of line N lines down.
- set_up
- Moves cursor to the start of line N lines up
- underline256
- Set underline color as 256 color.
- underline_
rgb - Set underline color as rgb. R, G, and B muse be values in range 0..256.
Enums§
- Cursor
Style - Defines the cursor style.
- Selection
- Specifies the selection buffer.
Constants§
- BACKSPACE
- Moves the cursor left by one positoin.
- BELL
- Produces terminal bell (audio or visual).
- BLACK_
BG - Set the background color to black (dark black).
- BLACK_
FG - Set the foreground color to black (dark black).
- BLINKING
- Set blinking mode.
- BLUE_BG
- Set the background color to blue (bright blue).
- BLUE_
DARK_ BG - Set the background color to dark blue.
- BLUE_
DARK_ FG - Set the foreground color to dark blue.
- BLUE_FG
- Set the foreground color to blue (bright blue).
- BOLD
- Set bold text mode (on some terminals may be just brighter color).
- BRACKETED_
PASTE_ END - Input code for bracketed paste end.
- BRACKETED_
PASTE_ START - Input code for bracketed paste start.
- CARRIAGE_
RETURN - Moves cursor to the start of the line. Same as
\r. - CLEAR
- Erases the whole screen and the scrollback buffer and moves cursor to the top left.
- CSI
- Control Sequence Introducer: Start of CSI sequence.
- CUR_
LOAD - Restores the cursor position to the last saved position (this is single
save slot, not stack). The position can be saved by
CUR_SAVE. - CUR_
SAVE - Saves the cursor position (this is single save slot, not stack). Position
can be later restored by
CUR_LOAD. - CYAN_BG
- Set the background color to cyan (bright cyan).
- CYAN_
DARK_ BG - Set the background color to dark cyan.
- CYAN_
DARK_ FG - Set the foreground color to dark cyan.
- CYAN_FG
- Set the foreground color to cyan (bright cyan).
- DCS
- Device Control String: Start of DCS sequence.
- DELETE
- Does nothing.
- DISABLE_
ALTERNATIVE_ BUFFER - Disables the laternative buffer and loads the previous contents of the default buffer.
- DISABLE_
BRACKETED_ PASTE_ MODE - Disables bracketed paste mode that was enabled with
ENABLE_BRACKETED_PASTE_MODE. - DISABLE_
FOCUS_ EVENT - Disables sending event on focus gain.
- DISABLE_
LINE_ WRAP - Disables line wrapping.
- DISABLE_
MOUSE_ XY_ ALL_ TRACKING - Disables mouse tracking for X and Y coordinate on press, release, drag and move.
- DISABLE_
MOUSE_ XY_ DRAG_ TRACKING - Disables mouse tracking for X and Y coordinate on press, release and drag.
- DISABLE_
MOUSE_ XY_ EXT - Disables extension to send mouse inputs with proper CSI sequences.
- DISABLE_
MOUSE_ XY_ PIX_ EXT - Disables extension to send mouse inputs in different format as position in pixels.
- DISABLE_
MOUSE_ XY_ PR_ TRACKING - Disables mouse tracking for X and Y coordinate on press and release.
- DISABLE_
MOUSE_ XY_ TRACKING - Disables mouse tracking for X and Y coordinate on press enabled by
ENABLE_MOUSE_XY_TRACKING. - DISABLE_
MOUSE_ XY_ URXVT_ EXT - Disables URXVT mouse extension.
- DISABLE_
MOUSE_ XY_ UTF8_ EXT - Disables extension to send mouse inputs in format extended to utf8 two byte characters.
- DISABLE_
REVERSE_ COLOR - Disables reverse color for the whole terminal display.
- DONT_
LIMIT_ PRINT_ TO_ SCROLL_ REGION - Don’t limit the printing area.
- DOUBLE_
CHAR_ HEIGHT_ DOWN - Makes this line characters twice as large overlapping with the line below.
- DOUBLE_
CHAR_ HEIGHT_ UP - Makes this line characters twice as large overlapping with the line above.
- DOUBLE_
CHAR_ WIDTH - Makes this line character twice as wide (but not twice as tall).
- DOUBLE_
UNDERLINE - Set double underline mode.
- ENABLE_
ALTERNATIVE_ BUFFER - Enables alternative buffer.
- ENABLE_
BRACKETED_ PASTE_ MODE - Enables bracketed paste mode. In this mode, pasted text is treated verbatim.
- ENABLE_
FOCUS_ EVENT - Enables sending event on focus gain.
- ENABLE_
LINE_ WRAP - Enables line wrapping.
- ENABLE_
MOUSE_ XY_ ALL_ TRACKING - Enables mouse tracking for X and Y coordinate on press, release, drag and move. Also track scroll events.
- ENABLE_
MOUSE_ XY_ DRAG_ TRACKING - Enables mouse tracking for X and Y coordinate on press, release and drag. Also reacts to mouse scroll wheel.
- ENABLE_
MOUSE_ XY_ EXT - Enables extension to send mouse inputs using CSI codes.
- ENABLE_
MOUSE_ XY_ PIX_ EXT - Enables extension to send mouse inputs as valid CSI sequences. The position is in pixels.
- ENABLE_
MOUSE_ XY_ PR_ TRACKING - Enables mouse tracking for X and Y coordinate on press and release and track mouse scroll events. Also reports modifiers.
- ENABLE_
MOUSE_ XY_ TRACKING - Enables mouse tracking for X and Y coordinate on press (mouse down).
- ENABLE_
MOUSE_ XY_ URXVT_ EXT - Enables URXVT mouse extension. The terminal will send valid CSI codes.
The codes may have different meaning when printed. This is why it is not
recommended, rather use
ENABLE_MOUSE_XY_EXT. - ENABLE_
MOUSE_ XY_ UTF8_ EXT - Enables extension to send mouse inputs in format extended to utf8 two byte characters. Advantage of this mode is that the coodinates are now limited to 2015 instead of only 223.
- ENABLE_
REVERSE_ COLOR - Enables reverse color for the whole terminal display.
- ERASE_
ALL - Erases the whole screen and the scrollback buffer.
- ERASE_
BUFFER - Erase the scrollback buffer.
- ERASE_
FROM_ LN_ START - Erases from the start of the line to the cursor.
- ERASE_
FROM_ START - Erases from the start of the screen to the cursor.
- ERASE_
LINE - Erases the entire line.
- ERASE_
SCREEN - Erases the entire screen.
- ERASE_
TO_ END - Erases from the cursor to the end of the screen.
- ERASE_
TO_ LN_ END - Erases from cursor to the end of the line.
- ESC
- The escape character.
- FAINT
- Set dim/faint text mode.
- FORMFEED
- Indicates new page, usualy has no use in terminal.
- FULL_
RESET - Full terminal reset. Clear the screen, buffer, reset all modes, …
- GRAY_BG
- Set the background color to gray (bright black).
- GRAY_
BRIGHT_ BG - Set to background color to bright gray (dark white).
- GRAY_
BRIGHT_ FG - Set to foreground color to bright gray (dark white).
- GRAY_FG
- Set the foreground color to gray (bright black).
- GREEN_
BG - Set the background color to green (bright green).
- GREEN_
DARK_ BG - Set the background color to dark green.
- GREEN_
DARK_ FG - Set the foreground color to dark green.
- GREEN_
FG - Set the foreground color to green (bright green).
- HIDE_
CURSOR - Makes the cursor invisible.
- HTAB
- Horizontal tabulator, moves cursor to the next stop. Same as
\t - INVERSE
- Set inverse mode (inverse foreground and background).
- INVISIBLE
- Set invisible mode.
- ITALIC
- Set italic mode.
- LIMIT_
PRINT_ TO_ SCROLL_ REGION - Limit printing area only to scroll region.
- LOAD_
SCREEN - Loads the last saved screen and the cursor position.
- MAGENTA_
BG - Set the background color to magenta (bright magenta).
- MAGENTA_
DARK_ BG - Set the background color to dark magenta.
- MAGENTA_
DARK_ FG - Set the foreground color to dark magenta.
- MAGENTA_
FG - Set the foreground color to magenta (bright magenta).
- MOVE_
HOME - Moves cursor to the top left of the screen.
- NEWLINE
- Moves the cursor to the start of the next line. Same as
\n. - OSC
- Operating System Command: Start of OSC sequence.
- OVERLINE
- Set ouverline mode.
- RED_BG
- Set the background color to red (bright red).
- RED_
DARK_ BG - Set the background color to dark red.
- RED_
DARK_ FG - Set the foreground color to dark red.
- RED_FG
- Set the foreground color to red (bright red).
- REQUEST_
CHAR_ SIZE - Request size of single character on screen in pixels.
- REQUEST_
CURSOR_ COLOR - Requests the cursor color.
- REQUEST_
CURSOR_ POSITION - Request the current cursor position. In some terminals, the report may be ambigous with F3 key press with modifiers.
- REQUEST_
CURSOR_ POSITIO N2 - Request the current cursor position. Difference from
REQUEST_CURSOR_POSITIONis that the response is not ambigous, but it is not supported by some terminals that supportREQUEST_CURSOR_POSITION. - REQUEST_
DEFAULT_ BG_ COLOR - Requests the default background color.
- REQUEST_
DEFAULT_ FG_ COLOR - Requests the default foreground color.
- REQUEST_
DEVICE_ ATTRIBUTES - Request the device attributes.
- REQUEST_
SELECTION - Requests the copy/paste selection data from default buffer.
- REQUEST_
SIXEL_ COLORS - Request the number of sixel color registers.
- REQUEST_
STATUS_ REPORT - Request the device status.
- REQUEST_
TERMINAL_ NAME - Requests the terminal name and version.
- REQUEST_
TEXT_ AREA_ SIZE - Request size of the text area in characters.
- REQUEST_
TEXT_ AREA_ SIZE_ PX - Request the text area size of the terminal in pixels.
- RESET
- Resets all the text modes (colors and styles).
- RESET_
ALL_ COLOR_ CODES - Resets all the color codes to their default colors.
- RESET_
BG - Reset the background color.
- RESET_
BLINKING - Reset
BLINKINGmode. - RESET_
BOLD - Reset
BOLDandFAINTmode. - RESET_
CHAR_ SIZE - Resets this line character size.
- RESET_
CURSOR_ COLOR - Resets the cursor color.
- RESET_
DEFAULT_ BG_ COLOR - Resets the default background color.
- RESET_
DEFAULT_ FG_ COLOR - Resets the default foreground color.
- RESET_
FG - Reset the foreground color to the default foreground color.
- RESET_
INVERSE - Reset
INVERSEmode. - RESET_
INVISIBLE - Reset
INVISIBLEmode. - RESET_
ITALIC - Reset
ITALICmode. - RESET_
OVERLINE - Reset
OVERLINEmode. - RESET_
SCROLL_ REGION - Reset the scroll region.
- RESET_
STRIKETROUGH - Reset
STRIKETROUGHmode. - RESET_
UNDERLINE - Reset
UNDERLINEandDOUBLE_UNDERLINEmode. - RESET_
UNDERLINE_ COLOR - Reset the underline color.
- SAVE_
SCREEN - Saves the visible part of the screen buffer and the cursor position.
- SHOW_
CURSOR - Makes the cursor visible.
- SS3
- Single shift three.
- ST
- String terminator. Terminates for example DCS.
- STRIKETROUGH
- Set striketrough mode.
- UNDERLINE
- Set underline mode.
- UP_SCRL
- Moves cursor one line up, ‘scrolling’ if needed.
- VTAB
- Vertical tabulator, moves the cursor to the next vertical stop.
- WHITE_
BG - Set the background color to white (bright white).
- WHITE_
FG - Set the foreground color to white (bright white).
- YELLOW_
BG - Set the background color to yellow (bright yellow).
- YELLOW_
DARK_ BG - Set the background color to dark yellow.
- YELLOW_
DARK_ FG - Set the foreground color to dark yellow.
- YELLOW_
FG - Set the foreground color to yellow (bright yellow).
Traits§
- GetString
- Trait for getting string from &str and String.
Functions§
- define_
color_ code - Defines color for the given color code.
- request_
selection - Requests selection for the first available of the given selection buffers. If empty requests the default buffer selection.
- set_
cursor - Sets cursor to the given style.
- set_
cursor_ color - Sets the color of the cursor.
- set_
default_ bg_ color - Sets the background color of terminal.
- set_
default_ fg_ color - Sets the default foreground color.
- set_
selection - Sets the given selection buffers. If empty sets the default selection buffers.