The magazine of the Melbourne PC User Group
Beginners' Bytes: Part 10
Ron Wilby
|
 |
Welcome to anybody has the time and patience to read this stuff. I'm still getting lots of phone calls, so we know there are a few readers out there.
Last month we finished with a few lines about the Installable Device Driver, ANSI.SYS. I hope you will remember that there are "resident" device drivers, which are built in to DOS, and "installable" device drivers. These are separate files, supplied as part of your DOS package, which you install by way of your Startup File, CONFIG.SYS. To install ANSI.SYS every time you boot up your computer, put this line in your CONFIG.SYS file:
DEVICE=C:\DOS\ANSI.SYS
This assumes that ANSI.SYS is in the DOS directory of your C: drive.
The ANSI.SYS Device Driver
ANSI.SYS is a device driver you can use to give DOS more control over your computer's display. ANSI.SYS fits between your keyboard and the computer's Central Processing Unit (CPU), and between the CPU and your display. Don't forget that to use ANSI.SYS you will need to load it with your startup files, as described above or see Part 7 of Beginners' Bytes. After ANSI.SYS is loaded, all input from the keyboard and output to the screen are routed through the ANSI.SYS driver. With this device driver you can
- Use the PROMPT command to personalise your system prompt
- Move the cursor anywhere on screen
- Change the video attributes of your screen display
- Create colourful screen messages
- Use Scan Codes to redefine the functions of your keys
To use ANSI.SYS you will need some information about the colour attributes (figures you put in your commands to get a particular colour) and about the escape sequences which you can use. This is well-documented in that excellent DOS 5 manual, but if you have only DOS 6 then you must use that creaking Help system for this information. If you don't have the DOS 5 manual, a desirable alternative for DOS 6 users would be a trip to the bookshops. There you'll find something like the MS-DOS 6 Users Guide, from which you will also get lots of other useful knowledge.
ANSI.SYS Commands
Commands to ANSI.SYS are called escape sequences, because they start with the escape (Esc) character. This brings us to a problem. You can't type an ANSI escape sequence at the DOS prompt like other commands. If you try this, DOS's response to the Esc key is to cancel the current operation and move the cursor down to the next line.
Creating the Esc Character
So, what to do? There are three ways to go.
- Put the ANSI escape sequence into a text file, then use the TYPE command to run it.
- Use the PROMPT command.
- Use a batch program and put the escape sequence in an ECHO command.
To put this escape character into an unformatted text (non-document) file you can use any text editor that gives you a way to create the Esc character. For example, DOS Editor uses Ctrl+P then Esc, followed by the left square bracket. MS Word and some other word processors use Alt+27 followed by the left square bracket. Or type 27 on the numeric keypad at the right of your keyboard while holding down the Alt key. For other word processors, check your manual to see if there is a documented way to create the Esc character. Whichever way you use, the Esc character on screen should be a small
left-pointing arrow, followed by the left square bracket.
Using the PROMPT Command
The second way to start an escape sequence is by using the PROMPT command at the DOS prompt. You type PROMPT
(string), where string is a series of characters you want to use as a prompt, such as "What is Your Command, Master?" DOS provides a set of sub-commands, called the PROMPT sub-commands, which PROMPT can use to talk with
ANSI.SYS. Most important, one of these sub-commands, $e, is the escape character. There is also $p (current drive and path) and $g (greater-than symbol >). Thus your on-screen prompt could be created by
PROMPT=$p$g
and would show the current drive and path followed by >. I personally use this to get, for example, C:\QUICKEN5> as my prompt. Note that lowercase characters must be used in these commands.
The third method, using a batch program, we'll leave until we've had a look at batch programs (batch files).
Other ANSI.SYS Facilities
Cursor-movement commands are available, so that you can, for example, put the cursor at the centre of the screen. Then, using the PROMPT commands, you can add the current date and time. There are screen commands (numbers) to make your display
high intensity, blinking or reverse video and also to change your foreground (characters) and background screen colours. With these commands you can colour your prompt to make it more exciting. You can redefine the functions of your keys. You can make those useless F11 and F12 keys do something you want. For example, you might make F11 change to your database directory and start your database, F12 could do the same with your word processor.
Having Fun
Before you start mucking about, make a copy of your startup files, CONFIG.SYS and AUTOEXEC.BAT. Put these on a bootable floppy, i.e. one formatted with the system files. Then, if you get into trouble, you can Ctrl+Alt+Del and reboot from the floppy and so get yourself back in business. Of course, there is the less desirable alternative of phoning Ron for help. Then, get out your DOS 5 Manual or your newly purchased paperback DOS User's Guide and do something with your prompt. Change the colours of your screen and have a good play around. You will learn about your computer and maybe
improve its usefulness. Don't forget, you will need to reboot (reset or Ctrl+Alt+Del) to see the effect of any changes you make to startup files. For a start, try putting this line into your AUTOEXEC.BAT file:
prompt=$e[36;40m $p$g
That's my prompt (this week). Or try this
prompt=$e[32;40mYes Master $e[36;44m$p$g
Your DOS manual should explain the symbols used, but to get you started,
- $e is the Esc character
- m sets screen attributes (colours)
- $p is the drive and path
I haven't given you a complete coverage of all this. One day I'll write a series about what you can do with ANSI.SYS!
Batch Files
DOS calls them Batch Programs, which is a better name. A batch file is an easy way of having DOS carry out a series of oft-used commands, one after another. For example, most of us use a series of commands to start a program. If you start your programs from a menu, this series of commands is still being carried out by your menu setup. The advantage of a batch file is that you have only to remember and type one command instead of several.
It's amazing how often you read instructions like just write a batch file or
Edit your AUTOEXEC.BAT. For a beginner, this can be a daunting prospect, so let's see if we can show you how it's all done. First we'll define a batch file. It's a file whose name has a .BAT extension, like WP51.BAT. DOS recognises these files as containing a series of commands which are to be executed one after another. To have DOS execute WP51.BAT, and thus start Word Perfect 5.1, I just type WP51 and Enter.
Finding an Editor
For users of DOS 5 or higher, you should use the Dos Editor to write batch files. It's an excellent text editor and easier than messing with word processors. To write a batch file with your word processor you must put it into ASCII (pronounced ass-key) mode. This is referred to as Non-Document, Plain Text, Unformatted and various other names. This is because word processors put in lots of extra characters, which you don't see on screen. To see what I mean, take any document from your word processor, get to your DOS prompt, and issue the command
TYPE {document name}
You will see a lot of strange symbols which DOS cannot handle. These are instructions to the printer or housekeeping characters of some kind. DOS doesn't like them and hangs or gets the sulks, therefore you must use ASCII. Don't forget Norton, PC Tools and the like have text editors.
Writing Batch Files
Having found the right editor, now you can write the file. What you must do is to write your first command, which might be just
C:
to make sure you are logged on to the correct drive. Put this command on the first line. Next, you will want to change to the correct directory, so your next command would be
cd\(directory name)
Put this command on the next line. Do not add any commas or punctuation. Then, on the next line you will put the command to start your program, such as WP51, Lotus etc.
One word of caution! Do not name your batch file with the name of any DOS command, because DOS looks for files with extensions of COM, EXE and .BAT in that order. So, if you call your batch file
FORMAT.BAT, it will never be executed, because DOS will always find FORMAT.COM first and execute that file.
Batch File Examples
For example, in starting my word processor from my (DOS 5) menu, I am actually starting a small batch file which I have put in place to reduce the number of keystrokes (and errors). The file is
CD\WORK
GMKWP
WS
The first line changes the default directory to the one I use for such tasks as these articles.
The second line loads Grammatik 5, my writing style and spelling checker, so that I can call it up from within any document I am writing. It's a wonderful help to any writer.
The third line loads my word processor, WordStar.
The whole file is called WORD.BAT, and typing WORD and pressing Enter at the DOS prompt tells DOS to carry out the three lines of commands one after the other. Alternatively, selecting "Word Processor" from the DOS menu issues the command
WORD
See how much easier life becomes with a little batch file?
Another example from the DOS 5 manual, a batch file to back up files to floppy disks. The file is:
CD\WORK\DOCFILES
COPY *.TXT
A: CD\REPORTS\XFILES
COPY *.TXT A:
The first line changes directory, the second line orders DOS to copy all files with the extension .TXT on their names to the floppy disk in drive A:. The third and fourth lines repeat the above for a different directory. The four lines will be executed one after the other.
More About Batch Files
Batch files do not stop executing until there are no more commands left to execute. This means that all the time I have WordStar running, WORD.BAT is hanging around waiting in the wings until the "Start WordStar" command (WS) has finished. Thus when I decide to exit WordStar, control is passed back to WORD.BAT, which having no more commands left, hands control back to DOS.
Here lies an opportunity for you to make things happen. You could add some commands to back up your work automatically or load some other program to follow WordStar. You could flash some message on screen or do whatever your imagination allows.
There is much more that I could tell you about batch files, but that should come later. Perhaps we could use the whole Beginners' Column one month soon and talk more about them.
Reprinted from the July 1994 issue of PC Update, the magazine of Melbourne PC User Group, Australia
|