Sending Character Graphics

In Chapter 6 (p. 140), I described how to handle spawned programs that generate character graphics. It is occasionally useful to generate character graphics from the script itself. Expect provides no built-in support for doing this. It is not necessary because you can call external programs such as tput.[45] For example, the cup operation moves the cursor. The following command moves it to row 23, column 4:

send_user -raw [exec tput cup 23 4]

Executing many calls to tput can be slow because it is a separate program. However, its different outputs can be saved in variables and reused, thereby avoiding excessive calls of exec. More sophisticated handling is possible with Curses extensions to Tcl. These are listed in the Tcl FAQ.

[45] Probably a more significant reason that Tcl scripts do not perform character graphics is because of Tk, a Tcl extension for the X Window System. Tk is so easy to use that it is hard to justify spending time writing character-graphic interfaces when the same amount of time can produce a much better interface in X. I will describe the use of Tk with Expect in Chapter 19 (p. 428).

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.