Use ANSI sequences to:
You can use ANSI sequences to creaty fancy prompts or text screens or even text mode animated screens (though it may take several days to create one ANSI animated screen).
For ANSI sequences to be shown, they have to be sent to the screen.
You may use either
ECHO or a combination of
ECHO OFF, or even any combination of these methods within a single batch file.
The only requirement to use ANSI sequences is the line:
in your CONFIG.SYS, at least for DOS systems.
Or use some other ANSI "interpreter", like ANSI.COM, by Michael J. Mefford.
OS/2 command prompts do not need ANSI.SYS, since the ANSI functions are built in the command processor.
To use ANSI sequences on DOS command prompts in OS/2 you'll still need to load ANSI.SYS in CONFIG.SYS.
It is possible to disable ANSI in OS/2 with the command
Likewise you may enable it again with
Windows NT doesn't support ANSI by default.
Check out George Roettger's home page for help on running ANSI.SYS in NT (plus many more NT tips).
Replace <Esc> with ASCII character 27 (see note) in text on screen (e.g.
TYPEd files or
ECHOed strings) or with $E in
Most DOS based editors will display the Escape character as a left arrow.
Most Windows based editors will display the escape character as a square.
|Note:||Inserting ASCII Character 27 (Esc):
• In EDIT, use
• In Notepad or Wordpad, copy and paste the Escape character from some reference file you can create using EDIT.
• In Norton Commander or File Commander's editor, use
• In E and EPM (OS/2) just type
• In UltraEdit, press
You may have to change the codepage to 437 in some editors.
You may combine as many text attributes as you see fit.
<Esc>[5m will give different results in different situations:
In plain DOS and in full screen OS/2 text mode it will result in blinking text.
In OS/2 and DOS windows it will result in a bright background.
PROMPT strings some extra ANSI sequeunces are available.
|Notes:||(1)||Use the COLOR command or CMD /T to set the default text colors in NT command line sessions|
|(2)||Learn how to change the looks of your command prompt by reading Microsoft's article: "HOW TO: Set the Command Processor Appearance in Windows XP".
Don't be fooled by the title, this works in older Windows versions too.
|<Esc>[0m||Reset all previous text attributes|
|<Esc>[1m||Bold or bright text|
|<Esc>[2m||Bold off (not reliable; use <Esc>[0m instead)|
|<Esc>[4m||Underlined (monochrome) or blue|
|<Esc>[5m||Blinking text or||bright background|
|<Esc>[8m||Invisible text||(Invisible text)|
|Notes:||(1)||DOS will display blinking text with <Esc>[5m, OS/2 windows will give a bright background, and OS/2 Full screen will start with a bright background but will switch to blinking text as soon as it loses focus.|
|(2)||Text made invisible on screen with <Esc>[8m will still be visible on screen prints.
It is therefore not recommended for hiding passwords etc., unless you use cursor positioning and then <Esc>[K to wipe the password from the screen completely, immediately after inputting it.
|<Esc>[r;cH||Position cursor at row r and column c|
|<Esc>[nA||Move cursor n rows up|
|<Esc>[nB||Move cursor n rows down|
|<Esc>[nC||Move cursor n columns forward (right)|
|<Esc>[nD||Move cursor n columns back (left)|
|<Esc>[6n||Show current cursor position|
|<Esc>[s||Save current cursor position|
|<Esc>[u||Restore previously stored cursor position|
|<Esc>[K||Clear to end of line|
|ANSI sequence||Video mode||ANSI sequence||Video mode|
|40x25 B/W text||<Esc>[=7l||disable wrap|
|40x25 color text||<Esc>[=13h
|320x200 16 colors|
|80x25 B/W text||<Esc>[=14h
|640x200 16 colors|
|80x25 color text||<Esc>[=15h
|640x350 2 colors|
|320x200 4 colors||<Esc>[=16h
|640x350 16 colors|
|320x200 2 colors||<Esc>[=17h
|640x480 2 colors|
|640x200 2 colors||<Esc>[=18h
|640x480 16 colors|
|320x200 256 colors|
|Note:||The l in <Esc>[=nl is a lower case L|
|inkey||specifies the macro's hotkey|
|outstring||specifies the keystrokes to be performed|
|65||81||<Esc>[65;81p||Replace "A" (ASCII 65) with "Q" (ASCII 81)
(AZERTY to QWERTY translation the hard way?)
|0;68||DIR;13||<Esc>[0;68;DIR;13p||Pressing F10 (extended ASCII 0;68) will result in "DIR" being typed, followed by <Enter> (ASCII 13)|
|Notes:||(1)||The keyboard redirection or keyboard macro will be active only when ANSI is active: in command prompt sessions and batch files.
It cannot be used within application programs.
|(2)||The keyboard redirection or keyboard macro is not permanent. You should re-execute the batch file that activates the macro every time you start a new command line session.|
Take a look at ANSIDEMO.BAT for some examples of cursor positioning and text attributes.
Shown below is a picture of the ANSI screen output for AN_APPLE.ANS, a fine example of ANSI art by Chris Blanton:
View it in text mode by changing to the right directory and using the following command:
There may be occasions where you don't know in advance if ANSI.SYS will be loaded or not.
You can check if ANSI.SYS was loaded using MEM /C but that only looks for ANSI.SYS or ANSI.COM.
Utilities like BATCHMAN do a better job since they search for functionality, not for a particular driver. (On the other hand, once you are using BATCHMAN, why not use that to display colored text etcetera? Unlike ANSI.SYS, BATCHMAN will even work in Windows 2000.)
In many cases ANSI.COM may be a better solution.
Like BATCHMAN, ANSI.COM was written by Michael J. Mefford.
When called - at the start of a (DOS) batch file - it will load only if no other ANSI "interpreter" is active. When loaded it will function just like ANSI.SYS would. At the end of the batch file, you may unload it again, freeing memory for other programs.
By using ANSI.COM, you can make sure that your batch files will display their fancy colors just the way you intended them to.
Carlos M. wrote BG.
Initially intended for Batch Games, it can be used to colorize console windows of any type.
It is a modern replacement for BATCHMAN, and unlike BATCHMAN it will even work in 64-bit environments.
When you want ANSI functionality for text "enhancements", have a look at Norman De Forest's EKKO, an ECHO enhancement that can process almost every PROMPT function including coloured text (even without ANSI driver).
And the best part is, it works just as well in Windows NT.
|page last uploaded: 18 November 2011, 11:25|