Technical article 111463

Adding color to screen console prompts.

OpenServer 5.0.5OpenServer 5.0.6UnixWare 7.1.1

Written · Last revised

Problem

How do I change my default screen command prompt from "$" or "#" to one with color?

Solution

As an example only:
The example system name is "scotest", I want to change the prompt
to show "scotest...>>" in color. First, create a file called
"/prompt.txt" which contains:
For SCO OpenServer 5:
^[[1;37;46m scotest...>>^[[1;37;40m

This will print the name in cyan, alter the "46" for others. Use "^[[0" for low intensity mode.

For SCO UnixWare 2 and UnixWare 7:

^[[=0F^[[=3G^[[0m scotest...>>^[[=7F^[[=0G^[[0m^[[J
Set the permissions:
# chmod 666 /prompt.txt

The characters in the file cannot simply be typed in as they appear in the examples above, so:

^[[=0F^[[=3G^[[0m scotest...>>^[[=7F^[[=0G^[[0m^[[J
cannot be typed as:

i for insert, then ^, then [, then [, then =, etc. etc.

it must be:

i for insert, Control + V, then Escape (this puts in "^["), then [, then =, then 0, then F, then Escape, then a for append, then Control + V, then Escape, then =, etc. etc.

Rather than type the above, the codes can be set via octal (see the man page for "ascii" for conversion tables). Create a file called "octal.sh" which contains (this should all be one line):

echo "\033\0133\061\007337\007346\0155 scotest...>>
\033\0133\061\007337\007340\0155" >prompt.txt

Make the file executable with "# chmod 755 octal.sh". Then run it as:

# ./octal.sh

This will create the SCO OpenServer 5 prompt file as above.

The escape codes to activate and deactivate the colors can be seen using the "setcolor" command on all the operating systems. Run the command and direct the output to a file, for example:

# setcolor >test1

Then use "vi" to look at the file and examine what numbers are required for what color.

To test, simply cat the file to the screen:

# cat /prompt.txt

Codes can also be checked by using the Escape key and then typing the remainder of the code (it might not be visible on screen) to see its effects. This might not work with all systems.

To activate the new prompt when a user logs in, edit the system "/etc/profile" file and add these lines to the end of the file:

...
...
PS1=`cat /prompt.txt`
export PS1

The system could be set up, for example, to make one console multiscreen show a prompt in red, for example, and then others in blue, or could print the process id of the shell or other information.

The "/etc/profile" file could look like:
...
if [ tty = /dev/tty01 -o tty = /dev/tty02 ]
then
        PS1=`cat /prompt.txt`
else
        PS1=`tty`-$$
fi
export PS1

NOTE: The above only works on character multiscreens and scoterms on OpenServer 5, and only character screens UnixWare. It does not work on redirected scoterms or dtterms on UnixWare.

See also

setcolor(1), setcolor(C), uname(C), tty(C), vi(C), ascii(M).

From the Xinuos technical article database, record 111463. Reproduced with permission. The original is at www.sco.com/ta/111463, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.