Skip to main content

Module codes

Module codes 

Source
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 the format! macro. Because these codes may expand either to &'static str or String you can use the GetString::get_string method to get String, or you can use AsRef<str>::as_ref method to get &str, or you can use Into<Cow<'static, str>>::into to 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§

CursorStyle
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_POSITION2
Request the current cursor position. Difference from REQUEST_CURSOR_POSITION is that the response is not ambigous, but it is not supported by some terminals that support REQUEST_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 BLINKING mode.
RESET_BOLD
Reset BOLD and FAINT mode.
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 INVERSE mode.
RESET_INVISIBLE
Reset INVISIBLE mode.
RESET_ITALIC
Reset ITALIC mode.
RESET_OVERLINE
Reset OVERLINE mode.
RESET_SCROLL_REGION
Reset the scroll region.
RESET_STRIKETROUGH
Reset STRIKETROUGH mode.
RESET_UNDERLINE
Reset UNDERLINE and DOUBLE_UNDERLINE mode.
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.