As with so many things in Unix, there is more than one way to achieve the same ends. A utility called tput can also be used to move the cursor around the screen, get back information about the status of the terminal, or set colours. man tput doesn't go into much detail about the available commands, but Emilio Lopes e-mailed me to point out that man terminfo will give you a huge list of capabilities, many of which are device independent, and therefore better than the escape sequences previously mentioned. He suggested that I rewrite all the examples using tput for this reason. He is correct that I should, but I've had some trouble controlling it and getting it to do everything I want it to. However, I did rewrite one prompt which you can see as an example: Section 12.8.
Here is a list of tput capabilities that I have found useful:
tput Colour Capabilities
Set a background colour using ANSI escape
Set a background colour
Set a foreground colour using ANSI escape
Set a foreground colour
tput Text Mode Capabilities
Set bold mode
turn on half-bright mode
begin underline mode
exit underline mode
Turn on reverse mode
Enter standout mode (bold on rxvt)
Exit standout mode
Turn off all attributes (doesn't work quite as expected)
tput Cursor Movement Capabilities
Move cursor to screen location X,Y (top left is 0,0)
Save the cursor position
Restore the cursor position
Output the number of lines of the terminal
Output the number of columns of the terminal
Move N characters left
Move N characters right
move left one space
non-destructive space (move right one space)
last line, first column (if no cup)
up one line
tput Clear and Insert Capabilities
Erase N characters
clear screen and home cursor
Clear to beginning of line
clear to end of line
clear to end of screen
insert N characters (moves rest of line forward!)
insert N lines
This is by no means a complete list of what terminfo and tput allow, in fact it's only the beginning. man tput and man terminfo if you want to know more.