Skip to content

ANSI Escape Sequences

Ford edited this page Jul 12, 2014 · 1 revision

Ansi Escape Sequences

Escape Sequence Description
ESC [ lines A Moves cursor up by lines lines (1 by default)
ESC [ lines B Moves cursor down by lines lines (1 by default)
ESC [ cols C Moves cursor rightward by cols columns (1 by default)
ESC [ cols D Moves cursor leftward by cols columns (1 by default)
ESC [ lines E Moves cursor to beginning of the line, lines (default 1) lines down.
ESC [ lines F Moves cursor to beginning of the line, lines (default 1) lines up.
ESC [ col G Moves the cursor to column col (absolute, 1-based).
ESC [ row ; col H Set cursor position. The values row and col are 1-based.
ESC [ n J Erase display. When n is 0 or missing: from cursor to end of display). When n is 1: erase from start to cursor. When n is 2: erase whole display and moves cursor to upper-left corner.
ESC [ n K Erase line. When n is 0 or missing: from cursor to end of line. When n is 1: erase from start of line to cursor. When n is 2: erase whole line and moves cursor to first column.
ESC [ n L Insert n (default 1) lines before current, scroll part of screen from current line to bottom.
ESC [ n M Delete n (default 1) lines including current.
ESC [ lines S Scroll screen (whole buffer) up by lines. New lines are added at the bottom.
ESC [ lines T Scroll screen (whole buffer) down by lines. New lines are added at the top.
ESC [ n X Erase n (default 1) characters from cursor (fill with spaces and default attributes).
ESC [ row ; col f Set cursor position (same as H). The values row and col are 1-based.
ESC [ a ; b r Set scrolling region from top=a to bottom=b. The values a and b are 1-based. Omit values to reset region.
ESC [ s Save cursor position (can not be nested).
ESC [ u Restore cursor position.
ESC [ 7 ; col h Enables line wrapping at column position. If col (1-based) is absent, wrap at column 80.
ESC [ 7 l Disables line wrapping. Lines wraps at the end of screen buffer.
ESC [ 25 h Show text cursor.
ESC [ 25 l Hide text cursor.
ESC [ 30…37 m Set ANSI text color

Terminal Colours

Color Name Color Code
Black 30
Blue 34
Green 32
Cyan 36
Red 31
Purple 35
Brown 33
Light Gray 37

Notes

  • ESC is \033 in C
Clone this wiki locally