| Bash Prompt HOWTO: $Revision: 0.97 $, $Date: 2007/10/20 11:39:20 $ | ||
|---|---|---|
| Prev | Chapter 6. Colours and Cursor Movement | Next |
Xterm and rxvt can be switched into line draw mode on the fly with the appropriate escape sequence. You'll need to switch back after you've output the characters you wanted or any text following it will be garbled. Prompts based on these output codes don't work on the console, instead producing the text equivalents. If you're building a prompt using these codes, use a case statement as I've shown in several prompts for the $TITLEBAR variable, and only turn on the line draw characters if you're in an X terminal.
The methods used here are ANSI escape sequences. tput probably has this capability, but I'm not familiar with it.
As you'll see in a later section, some fonts include line draw characters without the need for this trick: but installing those fonts and/or relying on their presence is another layer of complexity: this method of getting at line draw characters seems more reliable to me than counting on having specialty fonts installed.
To start a sequence of line draw characters, use an echo -e and the \033(0 escape sequence. Most of the characters worth using are in the range lower case "a" through "z". Terminate the string with another escape sequence, \033(B .
The best method I've found for testing this is shown in the image below: use the escgen script mentioned earlier in the HOWTO to show the 100 to 200 octal range, echo the first escape sequence, run the escgen script for the same range, and echo the closing escape sequence. The image also shows how to use this in a prompt.

Using escape sequences in RXVT (also works in Xterm and RXVT derivatives like aterm, which is used here) to produce line draw characters. The "escgen" script used above is given earlier in the HOWTO.