ptg10805159
Chapter 18 Exercises 713
to perform typical operations (clear the screen, move the cursor) on a wide variety of
terminals. On the other hand,cursesdoes help with some of the details that we’ve
addressed in this chapter.Functions areprovided bycursesto set raw mode, set
cbreak mode, turn echo on and off, and the like. Note that thecurseslibrary is
designed for character-based dumb terminals, which have mostly been replaced by
pixel-based graphics terminals today.
18.14 Summary
Te rminals have many features and options, most of which we’reable to change to suit
our needs. In this chapter, we described numerous functions that change a terminal’s
operation — namely,special input characters and the option flags.We also looked at all
the terminal special characters and the many options that can be set or reset for a
terminal device.
Thereare two modes of terminal input—canonical (line at a time) and
noncanonical. Weshowed examples of both modes and provided functions that map
between the POSIX.1 terminal options and the older BSD cbreak and raw modes. We
also described how to fetch and change the window size of a terminal.
Exercises
18.1 Write a program that callstty_rawand terminates (without resetting the terminal mode).
If your system provides thereset( 1 )command (all four systems described in this text do),
use it to restorethe terminal mode.
18.2 ThePARODDflag in thec_cflagfield allows us to specify even or odd parity.The BSD
tipprogram, however,also allows the parity bit to be 0 or 1. How does it do this?
18.3 If your system’sstty( 1 )command outputs the MIN and TIME values, do the following
exercise. Log in to the system twice and start thevieditor from one login. Use thestty
command from your other login to determine which valuesvisets MIN and TIME to
(sincevisets the terminal to noncanonical mode). (If you arerunning a windowing
system on your terminal, you can do this same test by logging in once and using two
separate windows instead.)