<--- Turn the page     (contents page)     Turn the page --->


More on ANSI

Implementing ANSI detection in batch files




In DHMag Volume 1 - Number 01 - page 3 and 8, Ben Lunt, the author of DHMag, covered the DOS prompt, and how to change the color of the DOS display when ANSI was loaded. In DHMag Volume 1 - Number 02 - page 14, I have discussed about detecting ANSI driver, using both batch script and programs that returns errorlevel. Now, let us see those programs in action, by writing batch scripts to make DOS more colorful!

It is very useful to have these small programs, in case you doubt that you have installed a copy of ANSI.SYS during a DOS session. I know you can always check by loading CONFIG.SYS into your favorite editor. But this can not be done when you want to load or set something, i.e. setting a colorful DOS prompt from a batch script. Suppose you are tired seeing that old black and white prompt with just a drive letter, full colon and greater than sign (or may be with a blackslash, or current directory name), and you want something new.

Here we want a 'DHMag' prompt with 'red' symbols before it. You could create a new batch script, and call it from AUTOEXEC.BAT, or insert this code right into AUTOEXEC.BAT, so this will be your default prompt every time you start a DOS session. Recall that the code for red is 31 and black is 40 (both decimal). We call our utility to check if ANSI is installed first, then decide using errorlevel whether we should call color prompt setting code. [Get ANSIDET.COM from DHMag #2, page 14. ed.]
   ansidet.com  > nul
   if errorlevel 1 goto setcolor
   goto exit
   :setcolor
   ...
   ...
   :exit
I named the program ANSIDET.COM, which we called on the first line of our batch script. To make the screen tidy, we use redirection on the first line. The output of ANSIDET.COM will just disappear using the DOS NULL device. Another way to do this is to edit the source code and recompile using NBASM.

On second line, we check if ANSI is installed. If so, ANSIDET will return 1, and we got a good signal, else we must jump to exit. That's all. You can insert anything you want on the line under the :setcolor

Here, we will code a prompt we have mentioned above. Here is how to do it:
   prompt $e[40;31m§§§§§$_$e[0;0mDHMag  $p$g
What exactly is going on here? Well, first we set the color to red on black, printing five "seperation" chars, a carriage return and line feed, setting back the color to default, and show DHMag on a new line following by current directory path and a greater than sign. Pretty simple huh? Yeah, be creative and make you own cool prompt, i.e. your favorite basketball team logo. ¥



<--- Turn the page     (contents page)     Turn the page --->

Page 8