ANSI X3.64 Command Reference

TCC includes support for ANSI Std X3.64, allowing you to manipulate the cursor, screen color, and other display attributes through sequences of special characters embedded in the text sent to the display. These sequences are called "ANSI commands". (For a general description of this feature, see ANSI Support.) Because of the design of Windows, TCC cannot provide ANSI X3.64 support to external applications. (If you are running Windows 10 Creators Update or later, TCC will enable the built-in console ANSI support.)

 

TCC supports most common ANSI X3.64 screen commands, but does not provide the complete set of options supported by some operating system's ANSI X3.64 drivers (for example, TCC does not include ANSI X3.64 key substitutions; that functionality is already provided with key aliases). This section is a quick reference to the ANSI X3.64 commands supported by TCC.

 

ANSI X3.64 support within TCC can be enabled or disabled with the ANSI Colors configuration option, or the SETDOS /A command. You can test whether ANSI X3.64 support is enabled with the _ANSI internal variable.

 

An ANSI X3.64 command string consists of three parts:

 

<ESC>[The ASCII character ESC, followed by a left bracket. These two characters must be present in all ANSI X3.64 strings.
parametersOptional parameters for the command, usually numeric. If there are multiple parameters, they are separated by semicolons.
commandA single-letter command. (Case sensitive!)

 

For example, to position the cursor to row 7, column 12 the ANSI X3.64 command is:

 

<ESC>[7;12H

 

The parameters part of this command is "7;12" and the command part is "H".

 

To transmit ANSI X3.64 commands to the screen you can use the ECHO command. The ESC character can be generated by inserting it into the string directly (if you are putting the string in a batch file and your editor will insert such a character), or by using the internal "escape" character (defaults: caret, [^]) followed by a lower-case "e".

 

For example, the sequence shown above could be transmitted from a batch file with either of these commands (the first uses an ESC character directly, represented below by "<ESC>"; the second uses ^e):

 

echo <ESC>[7;12H

echo ^e[7;12H

 

You can also include ANSI X3.64 commands in your prompt, using $e to send the <ESC> character.

 

Commands

 

The internal TCC ANSI X3.64 interpreter supports the subset of X3.64 commands below. Variable parameters are shown in lower-case italics, e.g., #. row and attr, and must be replaced with the appropriate decimal numeric value when using the commands. The default value for row, rows, col, and cols is 1.

 

<ESC>[rowsA

Cursor up by rows (default is 1)

<ESC>[rowsB

Cursor down by rows (default is 1)

<ESC>[b

Repeat the previous character

<ESC>[#b

Repeat the previous character # times

<ESC>[colsC

Cursor right by cols (default is 1)

<ESC>[colsD

Cursor left by cols (default is 1)

<ESC>[d

Move cursor to first row

<ESC>[rowd

Move cursor to row

<ESC>[E

Cursor down one line and to first column

<ESC>[rowsE

Cursor down by rows and to first column

<ESC>[F

Cursor up one line and to first column

<ESC>[rowsF

Cursor up by rows and to first column

<ESC>[row;colf

Set cursor position, same as "H" command

<ESC>[G

Move cursor to column 1

<ESC>[colG

Move cursor to column

<ESC>[H

Set cursor to top left

<ESC>[row;H

Move cursor to row, column 1

<ESC>[row;colH

Set cursor position (top left is row 1, column 1)

<ESC>[4h

Insert mode

<ESC>[?25h

Show cursor

<ESC>[J

Erase from cursor to end of display

<ESC>[0J

Erase from cursor to end of display

<ESC>[1J

Erase from start of display to cursor

<ESC>[2J

Clear whole screen

<ESC>[K

Clear from cursor to end of line

<ESC>[1K

Erase from start of line to cursor (inclusive)

<ESC>[2K

Erase line

<ESC>[L

Insert one blank line

<ESC>[#L

Insert # blank lines

<ESC>[l

Move cursor forward one tab

<ESC>[#l

Move cursor forward # tabs

<ESC>[4l

Overstrike mode

<ESC>[?25l

Hide cursor

<ESC>[M

Delete one line

<ESC>[#M

Delete # of lines

<ESC>[attr1;attr2;...m

Set display attributes; see table of attribute values below

<ESC>[L

Delete one character

<ESC>[#L

Delete # characters

<ESC>[s

Save cursor position (may not be nested)

<ESC>[#S

Scroll up

<ESC>[#T

Scroll down

<ESC>[u

Restore saved cursor position (or top-left if nothing saved)

<ESC>[?5W

Set tab at every 8 columns

<ESC>[?5;#W

Set tab at every # columns

<ESC>[X

Erase one character

<ESC>[#X

Erase # characters

<ESC>[Z

Move cursor back one tab

<ESC>[#Z

Move cursor back # tabs

<ESC>[?7h

Wrap lines at screen edge

<ESC>[?7l

Don't wrap lines at screen edge

<ESC>[21t

Send "^e]lTitle^e\" (the console's window title) to console input

<ESC>]0;TitleBEL

Set console title to "Title". BEL is the ASCII character 7

<ESC>]4;...BEL

Change color(s)

<ESC>]104;...BEL

Reset color(s)

<ESC>[@

Insert one blank character

<ESC>[#@

Insert # blank characters

<ESC>8

Restore cursor

<ESC>7

Save cursor

<ESC>[#;#;#...,~

Play sound

<ESC>c

Reset

<ESC>D

Index

<ESC>E

Next line

<ESC>H

Horizontal tab set

<ESC>M

Reverse index

 

 

Display Attributes

 

The m escape sequences set display attributes.  Attribute values used for the m command are:

 

0Restore all attributes to default
1Bright (high intensity) foreground color
2Normal intensity foreground color
4Bright (high intensity) background
5Bright (high intensity) background
7Reverse video
8Concealed (foreground becomes background)
22Bold off (foreground is not intense)
24Background is not intense
25Background is not intense
27Normal video
28Concealed off
30..37Foreground color
40..47Background color
90..97Bright foreground color
100..107Bright background color

 

Foreground Code

Background Code

Color

30

40

Black

31

41

Red

32

42

Green

33

43

Yellow

34

44

Blue

35

45

Magenta

36

46

Cyan

37

47

White

90

100

Gray

91

101

Bright red

92

102

Bright green

93

103

Bright yellow

94

104

Bright blue

95

105

Bright magenta

96

106

Bright cyan

97

107

Bright white

 

If you are setting multiple attributes, combine them into a single command (using the ; concatenation operator). The attribute settings are cumulative, and are independent of order (except code 0, reset to default).

 

Examples

 

Set bright red foreground without changing background:

 

 echo ^e[31;1m

 

Set the display to bright cyan on blue, and clear the screen:

 

  echo ^e[44;36;1m^e[2J

 

Set up a prompt which saves the cursor position, displays the date and time on the top line in bright white on magenta, and then restores the cursor position and sets the color to bright cyan on blue, and displays the standard prompt:

 

  prompt $e[s$e[1;1f$e[45;37;1m$e[K$d $t$e[u$e[44;36;1m$p$g