An Introduction To Embedded Tk (page 28 of 32)

[Previous Page][Next Page][Table of Contents]

12.2 The VT100 Terminal Emulator

The example named tkterm implements a VT100 terminal emulator. The tkterm program can be used as a direct replacement for the more familiar emulator programs xterm or rxvt.

The sources for tkterm are contained in three separate files. The main procedure is in tkterm.c. Tcl/Tk for constructing the main window for the application is in tkterm.tcl. Finally, the file getpty.c takes care of the messy details of allocating a pseudo-TTY for the emulator and invoking a shell in the pseudo-TTY. (Much of the code in getpty.c was copied from rxvt.)

The tkterm program simulates the VT100 display using an ordinary Tcl/Tk text widget. C routines in tkterm.c interpret the characters and escape sequences coming into the program and use ET() functions to insert characters into their proper places within the text widget. The tkterm.c file is almost 1000 lines long, and is mostly devoted to interpreting the VT100 escape codes.

The tkterm program is an example of an application that could not be coded in pure Tcl/Tk, since Tcl/Tk has no provisions for dealing with pseudo-TTYs or TTYs in ``raw'' mode. But even if it could, we would probably still want to use some C code, since it seems unlikely that a Tcl/Tk script would be able to process the VT100 escape sequences efficiently.

[Next Page][Table of Contents]