From ts@uwasa.fi Fri Mar 31 04:00:00 2000
Subject: Prompt file information
Date: Fri, 31 Mar 2000 04:00:00
From: ts@uwasa.fi (Timo Salmi)

1PROMPT.TXT prompt and related tips                Fri 31-March-2000
===================================
                                                 All rights reserved
                               Copyright (c) 1993-2000 by Timo Salmi

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland
Spam foiling in effect.  My email filter autoresponder will return a
required email password to users not yet in the privileges database.
....................................................................

  Ŀ
   This file belongs to TSBAT*.ZIP. Please do not distribute 
   this 1PROMPT.TXT file separately! If you see this file    
   distributed alone, please alert the SysAdmin immediately. 
  

You are free to quote brief passages from this file provided you
clearly indicate the source with a proper acknowledgment.

Comments and corrections are solicited. But if you wish to have
individual prompt usage consultation, please rather post your
question to a Usenet newsgroup like news:comp.os.msdos.programmer or
news:alt.msdos.batch. It is much more efficient than asking me by
email. I'd like to help, but I am very pressed for time. I prefer to
pick the questions I answer from the Usenet news. Thus I can answer
publicly at one go if I happen to have an answer. Besides,
newsgroups have a number of readers who might know a better or an
alternative answer. Don't be discouraged, though, if you get a reply
like this from me. I am always glad to hear from fellow MS-DOS
users.
--------------------------------------------------------------------

From ts@uwasa.fi Fri Mar 31 04:00:01 2000
Subject: 1PROMPT.TXT index
Date: Fri, 31 Mar 2000 04:00:01
From: ts@uwasa.fi (Timo Salmi)

INDEX

P1) Changing the shell prompt
P2) Redefining keys
P3) Ansi prompt art
P4) Debugging the prompt
--------------------------------------------------------------------

From ts@uwasa.fi Fri Mar 31 04:00:02 2000
Subject: Changing the shell prompt
Date: Fri, 31 Mar 2000 04:00:02
From: ts@uwasa.fi (Timo Salmi)

P1) If you have programs that can shell to dos it would be nice to
know whether you currently are in a dos shell or not. Else you might
call the same program again from the shell and eventually run out of
memory. There is a rather straight-forward trick for this. Assume
that your program is called prog.exe. You can always call the
program from a batch, say pro.bat. Include the following lines in
your batch:

  set _prompt=%prompt%
  set prompt=%_prompt%[in shell or whatever text]
  prog %1 %2 %3 %4 %5 %6 %7 %8 %9
  set prompt=%_prompt%
  set prompt=

The method will not work or will produce unexpected results if the
program itself manipulates the prompt when shelling to Dos. Some
(usually advanced) programs do.

Another trick to avoid double loading is shown in the following
skeleton
  if "%_loaded%"=="yes" exit
  set _loaded=yes
  prog %1 %2 %3 %4 %5 %6 %7 %8 %9
  set _loaded=
--------------------------------------------------------------------

From ts@uwasa.fi Fri Mar 31 04:00:03 2000
Subject: Redefining keys
Date: Fri, 31 Mar 2000 04:00:03
From: ts@uwasa.fi (Timo Salmi)

P2) A frequently asked question about ansi.sys is now does one use
it to redefine keyboard keys. Here is an example which redefines the
F1 key invoke the directory "dir" command, the F2 key to invoke the
"dir/w" command, and the F3 to type the Scandinavian letter .
   prompt $e[0;59;"dir";13p
   prompt $e[0;60;"dir/w";13p
   prompt $e[0;61;""p
   prompt $p$g

The last line is needed to restore the prompt in its usual format
(which I have as $p$g).

To cancel the definitions apply
   prompt $e[0;59;;p
   prompt $e[0;60;;p
   prompt $e[0;61;;p
   prompt $p$g

This system requires that you have ansi.sys loaded in your
config.sys file
   device=c:\dos\ansi.sys

A related FAQ (Frequently Asked Question) is how to exchange the .
and , keys.  here is how to do that
  @echo <ESC>[",";"."p<ESC>[".";","p
To reverse the effect, apply
  @echo <ESC>[",";","p<ESC>[".";"."p
This trick will not work for exchanging the CTRL and SHIFT keys.
They are not mappable this way.

Note that ansi.sys replacements like zansi.sys (which I normally use
myself) do not have the key-redefinition feature. This has one
advantages, that is protecting you against the so-called ansi bombs.

The 0;59 pair defines F1 because it is that key's scan code. To get
the scan codes of the different keys you need either a scan code
table or a program that gives the scan code of the key you have
pressed. One such program is SCANCODE.EXE. You can find it is
ftp://garbo.uwasa.fi/pc/ts/tsbase13.zip (or whatever version number
is the current).
--------------------------------------------------------------------

From ts@uwasa.fi Fri Mar 31 04:00:04 2000
Subject: Ansi prompt art
Date: Fri, 31 Mar 2000 04:00:04
From: ts@uwasa.fi (Timo Salmi)

P3) You can devise quite complicated ansi prompts to do flashy
things although much of this is rather computer entertainment than
serious usage. Let look at some examples

My ordinary prompt is the simple
   prompt $p$g
which displays the directory followed bu the > sign. Furthermore I
use bright yellow on black, but for that I apply echo <ESC>[40;33;1m

Let's build from that.
   prompt $d $t$_$p$g
Gives the date and the time on the first line ($d $t), then on the
second ($_) gives the current directory ($p) and the > sign ($g).

Lets take a little more complicated example next:
   prompt $e[s$e[1;69H$t$h$h$h$e[u$p$g
To also include the date use:
   prompt $e[s$e[1;54H$d$e[1;69H$t$h$h$h$e[u$p$g
This is of of the basic prompt tricks, and it puts the time (and
date) in the upper right corner of the screen. First the current
cursor position is stored ($e[s); the cursor is moved to row 1,
column 69 ($e[1;69H) the time is displayed ($t); the hundredths of a
second are deleted ($h$h$h); the original cursor position is
restored ($e[u); and finally the current directory and the > sign
are displayed ($p$g).

The next obvious step is to display the time in some garish reverse.
For the normal part of the prompt lets use my own default which is
bright yellow on black ($e[40;33;1m).
   prompt $e[s$e[1;69H$e[41;32;1m$t$e[40;33;1m$h$h$h$e[u$p$g
The time is displayed in bright green on red ($e[41;32;1m).

The interpretation of the following prompt is left as an exercise:
   prompt $e[s$e[H$e[43;30m$e[KDirectory $p $d $t $h$h$h$h $v
          $e[40;33;1m$e[2;1H$e[K$e[u$p$g
Note that you must have everything on one line only. The wrap here
is just for readability.

One example of an "entertainment" prompt just to give the general
idea:
   prompt $e[s$_$e[40;37m$e[34m$e[37m$_$e[34m
          $e[40;37m$_$e[34m$e[37m$e[40;33m $p$g
Note that you must have everything on one line only. The wrap here
is just for readability.

The difference in using the echo and the prompt for setting the
screen colors is that the echo is invoked only when you apply it,
but the prompt is called each time the dos prompt appears.
--------------------------------------------------------------------

From ts@uwasa.fi Fri Mar 31 04:00:05 2000
Subject: Debugging the prompt
Date: Fri, 31 Mar 2000 04:00:05
From: ts@uwasa.fi (Timo Salmi)

P4) If you are having problems you can "debug" your prompt by giving
the "set" command in MS-DOS which displays your environment
variables including the prompt variable.
