Category : Batch File Utilities - mostly for DOS
Archive   : BATDOC.ZIP
Filename : BH_8.DOC

 
Output of file : BH_8.DOC contained in archive : BATDOC.ZIP


BAT-HINT # 8

**************************************************************************

from the BATHINTS library... part of the BATPOWER CONFERENCE from:

THE PAINFRAME OPUS/FIDO 261/1004 LYNX OPUS/FIDO 134/27
&
Baltimore, Maryland (301) 488-7461 Cochrane, Alberta (403) 932-2750

**************************************************************************

ANSI.SYS COMMAND EXAMPLES

This BAT-HINT is comprised of an assortment of ANSI.SYS command examples,
and assumes that the user has read BAT-HINT #7 (ANSI.SYS ESCAPE SEQUENCES).
Please recall that you must install the ANSI.SYS device driver in your
config.sys file (and reboot) in order to use ANSI.SYS commands.


CURSOR CONTROL
--------------

The cursor may be easily controlled in batch files using ANSI.SYS commands.
Carefull manipulation of the cursor can provide a means whereby text may be
displayed at any location on the screen. A simple example of this control
is shown below:

center1.bat

echo off
cls
ESC[12;36H--CENTER--

Center1.bat moves the cursor to row 12 column 36 and displays the text
--CENTER-- in the middle of the screen. Simple enough. Now let's modify
this batch file to display not only --CENTER-- in the middle of the screen,
but also the words TOP and BOTTOM at their appropriate locations...

center2.bat

echo off
cls
ESC[12;36H--CENTER--ESC[;36H---TOP----ESC[24;36H--BOTTOM--

Note how more than one ANSI.SYS command may be placed on a single line so
long as each command is preceeded by an escape character and a left square
bracket. Note also that to position the cursor in row 1 the number 1 was
not necessary... only the semicolon to indicate that the number to follow is
a column designation. The ESC[#;#H command actually allows the row # range
to be 1-25. A further point to note is that it was not necessary in
center2.bat to display the lines in descending order... the center line
appeared first, then the top line and finally the bottom line. Thus by such
technique it is possible to display text anywhere in the screen at any time.
For example, using the utility KEY.COM which waits for the user to hit a key
(and optionally returns an errorlevel code equal to the ASCII DEC code of
that key), it is possible to "time" the display of text anywhere on the
screen, as shown in the next example:

center3.bat

echo off
cls
ESC[12;36H--CENTER--
key
ESC[;36H---TOP----
key
ESC[24;36H--BOTTOM--
key

The KEY.COM utility is available in the BATPOWER file area.

The next example incorporates the features of center3.bat and introduces
the use of the save cursor command (ESC[s), the erase to end of line command
(ESC[K) and the restore cursor position command (ESC[u)...

center4.bat

echo off
cls
ESC[12;36H--CENTER--ESC[s
key
ESC[;36H---TOP----
key
ESC[24;36H--BOTTOM--
key
ESC[uESC[K--center--ESC[25;1H
key

Center4.bat saves the cursor position of the text --CENTER-- ...before the
text is displayed... and later restores that position, erases line 12 from
column 36 to the end of the line, then displays the same text in lower case
and finally moves the cursor to the last line (#25) in column 1 so that the
prompt does not reappear in the midst of the display.

Similar cursor movement may be commanded using the move right, left, up and
down ANSI.SYS commands.


DISPLAY ATTRIBUTES
------------------

The text displayed by the batch file examples shown above may be changed to
high intensity (bold), blinking, reverse video, underlined and even made
invisible using the set attribute ANSI.SYS command (ESC[#m). The following
example demonstrates the use of these commands:

display1.bat

echo off
cls
echo normal
echo ESC[1mhigh intensityESC[m
echo ESC[4munderlinedESC[m
echo ESC[5mblinkingESC[m
echo ESC[7mreverseESC[m
echo ESC[8minvisibleESC[m

Note that each attribute must be turned off after it is turned on, using the
ESC[m command. An easier way to accomplish this is to incorporate the "turn
off" attribute command in the next command line, as shown below:

display2.bat

echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[0;4munderlined
echo ESC[0;5mblinking
echo ESC[0;7mreverse
echo ESC[0;8minvisibleESC[m

In a similar manner, several attributes may be turned on and off in a single
ANSI.SYS command, as shown below:

display4.bat

echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[4mhigh intensity & underlined
echo ESC[5mhigh intensity & underlined & blinking
echo ESC[7mhigh intensity & underlined & blinking & reverseESC[m

Note from display4.bat that the attribute is remembered... so that if the
previous attributes are not turned off, the next attribute specified will
incorporate all prior attributes. Display4.bat is equivalent to
display5.bat shown below:

display5.bat

echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[0;1;4mhigh intensity & underlined
echo ESC[0;1;4;5mhigh intensity & underlined & blinking
echo ESC[0;1;4;5;7mhigh intensity & underlined & blinking & reverseESC[m

Display5.bat differs from display4.bat only in that it manually turns off
all prior attributes (via attribute # 0) then turns the attributes on (it
also takes longer to write!). One last note... remember to turn off all
attributes before the batch file terminates as these attributes are carried
forward by DOS.

In a manner similar to that shown in the display?.bat examples (this is
where I get lazy) you can alter the foreground and background colors of the
displayed text.


DISPLAY MODE
------------

Let it be known that I accept no responsibility for damage or alteration to
any device attached or within any computer system in which the following
mode?.bat files are executed. I say this only because I haven't the
foggiest idea if switching modes with ANSI.SYS commands may damage or alter
some video cards or monitors or both. I simply haven't the resources to
check this out. The resolution and color capability of your display can be
set with ANSI.SYS commands. For example, to set your display to monchrome
and 25 rows by 40 columns (wide) display and echo the text string HELLO in
the middle of the screen (and then return to normal color mode), you could
use the following batch file:

mode1.bat

echo off
cls
echo ESC[0h
echo ESC[12;18HHELLO
key
echo ESC[3h

Note that when an ANSI.SYS mode command is issued, the display blanks...
this is the reason the batch file is paused with the KEY command, otherwise
when the mode is returned to normal color by the last line of the batch file
the display will be blanked, resulting in nothing more than a couple of
display skrinks ("skrink" is a term I use to describe the monitor state
during a mode switch and the high-pitched noise that ensues!). Once again,
other modes may be set in a similar manner with the appropriate code number.


KEY DEFINITIONS
---------------

The redefinition of keys on the keyboard is a relatively simple matter with
ANSI.SYS commands, and although such commands are not as easy to issue as
those of such programs as SUPERKEY, they are almost as powerfull and a lot
cheaper. For example, to redefine the key for the letter "a" to the letter
"b" (heaven only knows why you would want to do this!) you could create the
following batch file:

key1.bat

echo off
cls
echo ESC[97;98p

where 97 is the ASCII DEC code for the character "a" and 98 is the code for
the character "b". OK, now how to get it back to normal?... like this:

key2.bat

echo off
cls
echo ESC[97;97p

To redefine a key that was previously altered, just define it to the value
it was originally. Most people prefer to define keys that are not keys used
frequently... for example the function keys used alone or in combination
with the shift, control or alt keys. Function key codes used alone or in
combination with shift, control or alt, always begin with the number 0
separated from the another two digit number by a semicolon. For example the
ASCII DEC code for F8 is 0;66 and for F2 is 0;60 and for shift-F5 is 0;88.
So to define a shift-F5 as the character string "dir/w", which also happens
to be a valid DOS command, create the following batch file:

key3.bat

echo off
cls
echo ESC[0;88;"dir/w"p

But of course this will only result in the string "dir/w" being placed on
the command line when shift-F5 is keyed in... it would be nicer to include a
carriage return in the redefinition so that when shift-F5 is keyed in, dir/w
is execited immediately. To include a carriage return in the key
redefinition, place the ASCII DEC code for a carriage return (13) in the
ANSI.SYS command, as shown in the example below:

key4.bat

echo off
cls
echo ESC[0;88;"dir/w";13p

Now when shift-F5 is keyed in the command dir/w is executed. Again, to
return shift-F5 to normal, just define it as itself:

key5.bat

echo off
cls
echo ESC[0;88;0;88p

Any character string can be defined to a key, including batch filenames and
names of other executable files. If you call up executable files by key
redefinitions, remember that the executable program may have its own set of
definitions for that particular key or other keys you have redefined. You
can avoid key definition conflicts by chaining the batch file which defines
the keys to other batch files that restore the key(s) to the original
definition before actually executing the wanted program.

**************************** David Creasey...LYNX...134/27...(403) 932-2750