[Toc][Index]

ANSI Codes


This section is a quick-reference to commonly-used ANSI commands. 
An ANSI 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 strings. 
        parameters          Optional parameters for the command.  If there 
                            are multiple parameters they are separated by 
                            semicolons. 
        cmd                 A single-letter command.  The case of the 
                            letter IS meaningful. 
 
 For example, to position the cursor to row 7, column 12 the ANSI command 
 is: 

 
         ESC[7;12H
 
 
 To transmit ANSI commands to the screen with CMD.EXE, you should 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 CMD.EXE's internal 
 "escape" character (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; 
 the second uses ^e): 

 
         echo 
         echo ^e[7;12H
 
 
 You can also include ANSI commands in your prompt, using $e to transmit 
 the ESC character.  You can NOT use PROMPT to transmit ANSI commands to 
 the screen from a batch file (see PROMPT). 
 
 Commands 
        ESC[rowsA               Cursor up 
        ESC[rowsB               Cursor down 
        ESC[colsC               Cursor right 
        ESC[colsD               Cursor left 
        ESC[row;colH            Set cursor position (top left is row 1, 
                                column 1) 
        ESC[2J                  Clear screen 
        ESC[K                   Clear from cursor to end of line 
        ESC[row;colf            Set cursor position, same as "H" command 
        ESC[attr;attr;...m      Set display attributes; see table of 
                                attribute values below 
        ESC[s                   Save cursor position (may not be nested) 
        ESC[u                   Restore cursor position after a save 
 
 Display Attributes 
        0           All attributes off (normal white on black) 
        1           High intensity (bold) 
        2           Normal intensity 
        4           Underline (usually effective only on monochrome 
                    displays) 
        5           Blinking 
        7           Reverse Video 
        8           Invisible 
        30-37       Set the foreground color: 
                       30=Black   31=Red       32=Green   33=Yellow 
                       34=Blue    35=Magenta   36=Cyan    37=White 
        40-47       Set the background color, same values as above but 
                    substitute 40 for 30 etc. 
 
 Settings are cumulative, so (for example) to set bright red foreground 
 set all attributes off, then set red, then bold, use: 

 
         echo ^e[0;31;1m
 
 
 
 Examples 
 Clear the display attributes, then set the display to bright cyan on 
 blue, and clear the screen: 

 
         echo ^e[0;44;36;1m^e[2J
 
 
 Set up a prompt which saves the cursor position, displays the CMD.EXE 
 shell level, 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[0;45;37;1m$e[K($z) $d $t$e[u$e[0;44;36;1m$p$g
 
 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs