Telling The User About New Features
In the examples so far, the escape sequences were layered on top of the spawned process. In each case, the user must be informed of these new commands in order to take advantage of them. Indeed, the more obvious the underlying spawned process is, the more likely the user is to forget that there are extra commands available.
Printing out documentation while the program is running can be very helpful and is easy to do. The previous script showed one such example—printing out a list of choices when an escape prefix is entered. Here are some others.
The following extract is from a script that layers several commands on top of the traditional ftp client to enable it to perform recursive ftp. (Called rftp, this script comes with Expect as an example.) These new commands are entered as ~g (get recursively), ~p (put recursively), and ~l (list recursively).
puts "Once logged in, cd to the directory to be transferred and\
press:\n"
puts "~p to put the current directory from the local to the remote\
host\n"
puts "~g to get the current directory from the remote host to the\
local host\n"
puts "~l to list the current directory from the remote host\n"
if {[llength $argv] == 1} {
spawn ftp
} else {
spawn ftp [lindex $argv 1]
}When the script starts up, it prints the messages above, which describe the new commands. Then the script drops into an interact so that ftp can enter its usual dialogue. The tilde escape works well, because ftp does not use tilde for anything ...