home *** CD-ROM | disk | FTP | other *** search
- Designer Screens
- (PC World November 1985 by B. Alperson, A. Fluegelman, & L. Magid)
-
- Control over the video display constitutes far more than window
- dressing: The screen is the medium for supplying information to the
- user. A well-designed screen enhances not only the aesthestics but
- also the efficiency of program execution and information presentation.
- It helps locate the apporpriate instructions and interpret program
- output. It can put the final polish on a system.
-
- With DOS 2.0's display capabilities and screen control features,
- you can use graphics characters, redesign the DOS prompt, and control
- parameters such a inverse video, cursor location, foreground and
- background colors, screen width, and screen mode.
-
- Some people go to the trouble of writing elaborate menu programs
- in BASIC or another language. There is a simpler approach. The
- extended ASCII character set can help create custom menus. It includes
- solid lines (ASCII 179, 180, 193, 194, 195, 196 and 197), single-line
- corners (ASCII 191, 192, 217 and 218), double lines (ASCII 185, 186,
- 202, 230, 204, 205 and 206), double-line corners (ASCII 187, 188, 200
- and 201), and special graphics symbols such as the large dot (ASCII
- 249) and the right arrowhead (ASCII 16).
-
- If you hold down the Alt key while you type the desired ASCII
- number on the numeric keypad, you'll discover that you can access all
- the symbols above ASCII 127. The corresponding character appears as
- soon as you release the Alt key. If you are using a keyboard macro
- processor like ProKey, you'll have to hold down both Alt and Shift
- while you press the keys on the numeric keypad.
-
- The characters available depend on the editing technique you use
- to create batch files. DOS's COPY and EDLIN provide access to ASCII
- codes 128 through 254. IBM's Professional Editor makes available ASCII
- codes 1 through 6, 11, 12, 14 through 31 and 127 through 254. WordStar
- does not offer access to any of the codes.
-
- Several strategies can simplify menu construction. Initial layout
- can be done with Professional Editor to take advantage of its what-you-
- see-is-what-you-get-display and its rapid search-and-replace function
- capability. When you're relying on such an editor, using the Alt key
- to enter a long series of extended ASCII codes can be tedious. A long
- double line might require you to press and hold the Alt key, type 205,
- and release the Alt key 30 times. A better technique would to type 30
- asterisks and then replace them with character 205 via the editor's
- global search and replace.
-
- Professional Editor cannot, however, perform one necessary task.
- Many menus tend to be so large that you'll want to do what you can to
- avoid wasted lines on the screen. A DOS quirk causes many batch files
- to end with a double prompt, forcing the top line of the menu off the
- screen. This anomaly can be prevented by making a Ctrl-Z the last
- character of the last line of the ASCII file. Professional Editor
- cannot perform this operation, but EDLIN can. The final step in
- creating a menu with Professional Editor, then, is to bring it into
- EDLIN to add the terminating Ctrl-Z. Once the menu is saved as a
- text file, you can write it to the screen at any time using the DOS
- TYPE command. If you call your menu MENU.DSP, for example, you can
- display it by including the commands CLS and TYPE MENU.DSP in a batch
- file.
-
- Suppose you have added your own function key assignments for F1
- and F7 through F10 to the DOS default assignments for F2 through F6.
- F2 through F4 allow you to redisplay different segments of a previous
- command line. F2 plus a character redisplays all characters of the
- previous command up to the first occurrence of the character you typed.
- You can also display all remaining characters (F3), skip all characters
- up to a given character (F4), and enter the currently display command
- line without executing the command to edit it further (F5). The final
- DOS default (F6) types an end-of-file character, or Ctrl-Z, which is
- displayed as ^Z. We will assume that you have added the following
- assignments to the remaining functin keys: F1 is COPY, F7 is BASICA,
- F8 is the main menu display, F9 is A:, and F10 is B:.
-
- You can create a small ASCII display to remind yourself of these
- assignments. This requires nothing more than EDLIN. The first step
- is to invoke the editor with a new file name, such as EDLIN FK.ASC.
- You can begin immediately by sending EDLIN the command 1I to insert
- text starting at the first line. You then type the ASCII code for a
- double-line upper left corner (Alt-201), followed by 37 asterisks, the
- ASCII code for a double-line upper right corner (Alt-187) and Enter.
-
- You begin the next line with the double-line border (Alt-186),
- then the text (F1 COPY), 15 spaces, the text (F2 Type to char), the
- double-line border (Alt-186), and Enter. Enter the remaining lines
- containing text in the same way. The final line includes a bottom left
- double-line corner (Alt-200), 37 asterisks, and a bottom right double-
- line corner (Alt-188). After entering the last line, press Ctrl-Break
- to exit EDLIN's insert mode.
-
- The only task remaining before saving the display to a disk file
- is to change all the asterisks to the horizontal double-line character
- to finish the framing display. This is easily accomplished with the
- EDLIN command 1,8R* Ctrl-Z Alt-205. Typing E (Enter) saves the display
- and it is ready to use.
-
- Any time you wish to display the function key reminder on screen,
- just issue the command TYPE FK.ASC. You might, for example, include
- the command as the last line of any batch file that returns to DOS
- after running an application program. It could also be included as
- the last line in your AUTOEXEC.BAT file.
-
- DOS 2.0's PROMPT command provides additional screen control. Its
- simplest use involves changing a prompt. You can invoke it with the
- syntax PROMPT [prompt-text] from either the keyboard or a batch file.
- Prompt-text can consist of any of 13 arguments plus any text you want
- to insert into the prompt. Each argument must begin with a dollar
- sign. You can include the date ($d), time ($t), default ($n), path
- ($p), greater-than symbol ($g), less-than symbol ($l), DOS version
- number ($v), vertical bar ($b), double horizontal line ($q), dollar
- sign ($$), a carriage return/line feed sequence ($_), a backspace and
- erase ($h), and an Escape character ($e).
-
- Anything on the command line other than these arguments will be
- printed as part of the prompt. The command PROMPT $n$g (or just
- PROMPT), typed from the keyboard or included in a batch file, will
- produce the normal DOS prompt. But if you use the command PROMPT
- $d $n$g, the date will be included in the prompt, and it will appear,
- for example, as "Thu 8-14-85 A>".
-
- A more useful application would have the prompt report the current
- path (including the drive specifier) after you issue the command PROMPT
- $p$g. If you are in the \EDISK directory of drive C:, for example,
- this command will produce the prompt "C:\EDISK". You can include any
- text in the prompt command. The command "PROMPT Charlie's DOS, Current
- Directory: $p$g" would produce the prompt "Charlie's DOS, Current
- Directory: C:\EDISK>".
-
- Although controlling the prompt is useful, the PROMPT command's
- most important function may well be providing a gateway to an extremely
- powerful display driver called ANSI.SYS. ANSI.SYS lets you manipulate
- display functions precisely. You can control cursor position (in a
- fashion similar to using BASIC's LOCATE, PRINT and CLS commands) and
- foreground and background colors and inverse video (similar to using
- BASIC's COLOR and SCREEN commands). ANSI.SYS also reports on current
- cursor location (like BASIC's CSRLIN and POS commands) and offers
- several functions not available in BASIC. (ANSI.SYS also enables you
- to redefine keys, although this capability is negligible compared to
- that of such macro processors as ProKey, SuperKey, and Keyworks).
-
- In order for DOS to install the ANSI.SYS driver, the ANSI.SYS
- file must be on your system start-up dis. The system start-up disk
- must contain a file called CONFIG.SYS, and this file must contain the
- line DEVICE=ANSI.SYS.
-
- Each call to an ANSI.SYS function begins with an Escape code.
- Since PROMPT allows you to send an Escape code to DOS ($e), this
- command provides access to the ANSI.SYS commands. The syntax of
- ANSI.SYS (modified to make use of the PROMPT command) and its functions
- are shown in Table 1 below. The visual effects of various Set Graphics
- Rendition (SGR) function parameters are listed in Table 2.
-
- When you combine the power of the ANSI.SYS display driver with
- the PROMPT command, you can turn your system prompt into a useful
- display. The batch file PROMPT1.BAT shown below was created with
- EDLIN. It produces an informative display such that whenever you are
- in DOS, this prompt lets you see both the date and the path to the
- current directory. The prompt also shows the date the system was last
- revised and an indication that the system is waiting for a command.
-
- The first parameter specified in the PROMPT command ($e[s) saves
- the cursor position when a DOS command is invoked. The next parameter
- ($e[1;1H) moves the cursor to row 1, column 1, ensuring that the
- current date, the path and the date the system was last revised will
- appear at the top of the screen, regardless of where the cursor was
- when the command was initiated. The next cursor movement parameters
- ($e[1;33H and $e[1;67H) locate the path and revision information
- properly on row 1. The last cursor movement parameter ($e[u), which
- appears toward the end of the PROMPT command, returns the cursor to
- the position it was in before the DOS command was issued, at which
- point the system can begin writing the command prompt.
-
- Controlling the cursor with this scheme produces intriguing and
- useful results. If the DOS command does not generate screen output,
- the date/path/revision line will appear immediately above the command
- prompt. But any screen output will appear between the date/path/
- revision line and the command prompt. This display scheme helps focus
- the user's attention appropriately during day-to-day activities with
- DOS.
-
- The prompt also contains several ANSI.SYS commands that control
- video attributes to guide the eye efficiently to the desired
- information. The parameter $e[36m makes the date appear in cyan.
- (This command has no effect on an IBM Monochrome Display.) The next
- parameter ($e[K) erases to the end of row 1. Inverse video is then
- turned on ($e[7m) for the path information, making it the most salient
- information in the display. The character attributes are returned to
- normal status for the revision information ($e[0m), and high-intensity
- is turned on for the command prompt ($e[1m). Finally, character
- attributes are returned to normal status ($e[0m) at the end of the
- prompt.
-
- PROMPT1.BAT illustrates several characteristics of the PROMPT/
- ANSI.SYS system. You can string together any number of parameters on
- the same command line to produce any desired effect. Your only
- limitation is the 127-character maximum length of the DOS command
- line. Cursor movement commands may be interspersed with video
- attribute commands to create eye-catching displays. Finally, the
- extended ASCII set is available. For example, you can combine the
- double horizontal line (ASCII 205) with a right arrowhead (ASCII 16)
- to produce a "pointer."
-
- The PROMPT/ANSI.SYS system also enables you to control foreground
- and background colors in DOS. This feat is easy in BASIC, but any
- changes made in BASIC are removed when you return to DOS. Prior to
- DOS 2.0, control of colors in DOS required programming in assembly
- language. Now the conditional logic available in batch files and the
- display control provided by ANSI.SYS and PROMPT have eliminated this
- problem.
-
- SCREEN1.BAT gives you control over foreground and background
- colors while in DOS. You invoke the batch file with the syntax SCREEN
- foreground background. To produce white text on a blue screen, for
- example, you would type SCREEN WHILE BLUE. (Note that SCREEN1.BAT,
- and any program to control DOS screen colors, will not be effective
- if the DOS prompt contains color commands.)
-
- WHITE would be the value assigned to "%1" in SCREEN1.BAT, and the
- batch file would test this variable until it found a match on the line
- "IF WHITE==%1 GOTO FWHITE". The conditional logic would send control
- to the label ":FWHITE", which would set the foreground color. (Note
- that the test must be performed for both uppercase and lowercase
- strings. DOS is normally insensitive to case, but the batch file
- conditional that tests for matching strings is case-sensitive. You
- are searching for an exact match with a string, and uppercase and
- lowercase representations of the same word are legitimately different
- string values.)
-
- After setting the foreground color, an unconditional branch (GOTO
- BACK) sends control to the routine that sets the background color. A
- new test is performed on "%2", which would find a match at the line
- "IF BLUE==%2 GOTO BBLUE". ":BBLUE" would then set the background color
- and send control to the exit routine ":END". THe two "ECHO ON,ECHO
- OFF,CLS" sequences in this batch file are necessary to force each
- PROMPT/ANSI color change when "ECHO" is off.
-
- Notice the "ECHO Wait ..." lines that appear twice in this batch
- file. These are not trivial or cosmetic additions to the program. At
- its worst, this batch file takes about 15 seconds to complete. In such
- a situation, providing an indication that something is actually going
- on is a sound idea. Otherwise, someone using the batch file for the
- first time is likely to terminate it prematurely on the assumption that
- it's not working. Many operations have been brought to a grinding halt
- by the failure to include simple messages such as "Wait ..."
-
- The sluggish execution of this batch file is troublesome. If you
- think about the logic of the problem, you'll realize that you`re
- forcing the computer to do more work than necessary. It is clear that
- you need a branching strategy, but requiring as many as 31 IF string
- comparisons is probably not the best way to proceed. All you really
- need to do is go directly to the appropriate foreground routine, then
- to the appropriate background routine.
-
- SCREEN2.BAT is a more efficient and elegant version of SCREEN1.BAT.
- It replaces the conditional IF logic with unconditional GOTO logic,
- eliminating the need for all but two of the tests of string values.
- Not only is this batch file both shorter and more emotionally
- satisfying than its precursor, it runs with a worst-case time of six
- seconds -- an improvement of 9 seconds over its more cumbersome
- predecessor. Rethinking your logic after completing a program can
- frequently produce this kind of time savings, reaffirming the adage
- that no program is ever a total loss ...it can always be used as a
- bad example.
- - - - - -
-
- Table 1: Selected ANSI.SYS/PROMPT functions
-
- DOS manual Modified
- mnemonic syntax Purpose
-
- CUP PROMPT $e[#;#H Moves cursor to row #, column #
- CUU PROMPT $e[#A Moves cursor up # rows without changing
- column
- CUD PROMPT $e[#B Moves cursor down # rows without changing
- column
- CUF PROMPT $e[#C Moves cursor right # columns without
- changing row
- CUB PROMPT $e[#D Moves cursor left # columns without
- changing row
- SCP PROMPT $e[s Saves current cursor position so that it
- can be restored with RCP
- RCP PROMPT $e[u Returns cursor to position saved with SCP
- ED PROMPT $e[2J Clears screen and homes cursor
- EL PROMPT $e[k Erases from current cursor position to
- end of line
- SGR PROMPT $e[#;...;#m Sets character attributes for color,
- bold, underscore, blinking and inverse
- video (see Table 2 for values of #)
-
- - - - - -
- Table 2: Set Graphics Rendition (SGR) function parameters
-
- Effect Command Notes
- Attributes
- Normal PROMPT $e[0m All attributes are off; w on b
- High intensity PROMPT $e[1m
- Underscore PROMPT $e[4m IBM monochrome only
- Blinking PROMPT $e[5m
- Inverse video PROMPT $e[7m
- Invisible PROMPT $e[8m
-
- Foreground Color
- Black PROMPT $e[30m Gray in high intensity
- Blue PROMPT $e[34m
- Green PROMPT $e[32m
- Cyan PROMPT $e[36m
- Red PROMPT $e[31m
- Magenta PROMPT $e[35m
- Brown PROMPT $e[33m Yellow in high intensity
- White PROMPT $e[37m
-
- Background Color
- Black PROMPT $e[40m
- Blue PROMPT $e[44m
- Green PROMPT $e[42m
- Cyan PROMPT $e[46m
- Red PROMPT $e[41m
- Magenta PROMPT $e[45m
- Brown PROMPT $e[43m
- White PROMPT $e[47m
- - - - - -
- PROMPT1.BAT: Produces screen output showing current date, path,
- revision date and a "COMMAND=>" prompt.
-
- ECHO OFF
- PROMPT $e[s $e[1;1H$e[36mDate=>$d $e[K$e[7m$e[1;34HPath=>$p
- $e[1;67H$e[0mRev. 01/01/85$e[u$e[1mCOMMAND+>$e[0m
-
- - - - - -
- SCREEN1.BAT: To manipulate foreground and background colors in DOS
-
- ECHO OFF
- CLS
- ECHO Wait ...
- IF ZIP==%1ZIP GOTO BACK
- IF BLACK==%1 GOTO FBLACK
- IF black==%1 GOTO FBLACK
- IF RED==%1 GOTO FRED
- IF red==%1 GOTO FRED
- IF GREEN==%1 GOTO FGREEN
- IF green==%1 GOTO FGREEN
- IF BROWN==%1 GOTO FBROWN
- IF brown==%1 GOTO FBROWN
- IF BLUE==%1 GOTO FBLUE
- IF blue==%1 GOTO FBLUE
- IF MAGENTA==%1 GOTO FMAGENTA
- IF magenta==%1 GOTO FMAGENTA
- IF CYAN==%1 GOTO FCYAN
- IF cyan==%1 GOTO FCYAN
- IF WHITE==%1 GOTO FWHITE
- IF white==%1 GOTO FWHITE
- :FBLACK
- PROMPT $e[30m
- GOTO BACK
- :FRED
- PROMPT $e[31m
- GOTO BACK
- :FGREEN
- PROMPT $e[32m
- GOTO BACK
- :FBROWN
- PROMPT $e[33m
- GOTO BACK
- :FBLUE
- PROMPT $e[34m
- GOTO BACK
- :FMAGENTA
- PROMPT $e[35m
- GOTO BACK
- :FCYAN
- PROMPT $e[36m
- GOTO BACK
- :FWHITE
- PROMPT $e[37m
- GOTO BACK
- :BACK
- ECHO ON
- ECHO OFF
- CLS
- ECHO Wait ...
- IF ZIP==%2ZIP GOTO END
- IF BLACK==%2 GOTO BBLACK
- IF black==%2 GOTO BBLACK
- IF RED==%2 GOTO BRED
- IF red==%2 GOTO BRED
- IF GREEN==%2 GOTO BGREEN
- IF green==%2 GOTO BGREEN
- IF BROWN==%2 GOTO BBROWN
- IF brown==%2 GOTO BBROWN
- IF BLUE==%2 GOTO BBLUE
- IF blue==%2 GOTO BBLUE
- IF MAGENTA==%2 GOTO BMAGENTA
- IF magenta==%2 GOTO BMAGENTA
- IF CYAN==%2 GOTO BCYAN
- IF cyan==%2 GOTO BCYAN
- IF WHITE==%2 GOTO BWHITE
- IF white==%2 GOTO BWHITE
- :BBLACK
- PROMPT $n$g$e[40m
- GOTO END
- :BRED
- PROMPT $n$g$e[41m
- GOTO END
- :BGREEN
- PROMPT $n$g$e[42m
- GOTO END
- :BBROWN
- PROMPT $n$g$e[43m
- GOTO END
- :BBLUE
- PROMPT $n$g$e[44m
- GOTO END
- :BMAGENTA
- PROMPT $n$g$e[45m
- GOTO END
- :BCYAN
- PROMPT $n$g$e[46m
- GOTO END
- :BWHITE
- PROMPT $n$g$e[47m
- :END
- ECHO ON
- ECHO OFF
- CLS
-
- - - - - -
- SCREEN2.BAT: An improved version of SCREEN1.BAT
-
- ECHO OFF
- CLS
- ECHO Wait ...
- IF ZIP==%1ZIP GOTO BACK
- GOTO F%1
- :FBLACK
- PROMPT $e[30m
- GOTO BACK
- :FRED
- PROMPT $E[31m
- GOTO BACK
- :FGREEN
- PROMPT $e[32m
- GOTO BACK
- :FBROWN
- PROMPT $e[33m
- GOTO BACK
- :FBLUE
- PROMPT $e[34m
- GOTO BACK
- :FMAGENTA
- PROMPT $e[35m
- GOTO BACK
- :FCYAN
- PROMPT $e[36m
- GOTO BACK
- :FWHITE
- PROMPT $e[37m
- GOTO BACK
- :BACK
- ECHO ON
- ECHO OFF
- CLS
- ECHO Wait ...
- IF ZIP==%2GOTO END
- GOTO B%2
- :BBLACK
- PROMPT $n$g$e[40m
- GOTO END
- :BRED
- PROMPT $n$g$e[41m
- GOTO END
- :BGREEN
- PROMPT $n$g$e[42m
- GOTO END
- :BBROWN
- PROMPT $n$g$e[43m
- GOTO END
- :BBLUE
- PROMPT $n$g$e[44m
- GOTO END
- :BMAGENTA
- PROMPT $n$g$e[45m
- GOTO END
- :BCYAN
- PROMPT $n$g$e[46m
- GOTO END
- :BWHITE
- PROMPT $n$g$e[47m
- :END
- ECHO ON
- ECHO OFF
- CLS
-
-