Next: 8.1 I/O Function in Up: e Previous: 7.2 Programming a sound
This chapter deals with screen input and output that is not pixel based, but character based. When we say character, we mean a composition of pixels that can be changed depending on a charset. Your graphic card already offers one or more charsets and operates by default in text (charset) mode because text can be processed much faster than pixel graphic. There is more to do with terminals than to use them as simple (dumb) and boring text displays. I will describe how to use the special features that your linux terminal, especially the linux console, offers.
- printf, sprintf, fprintf, scanf, sscanf, fscanf
With these functions from you can output formatted strings to (standard output), (standard error) or other streams defined as FILE *stream (files, for example). Scanf(...) provides a similar way to read formatted input from .
- termcap
The TERMinal CAPabilitie database is a set of terminal description entries in the ASCII file /etc/termcap. Here you can find information about how to display special characters, how to perform operations (delete, insert characters or lines etc) and how to initialize a terminal. The database is used, for example, by the editor vi. There are view library functions to read and use the terminal capabilities (termcap(3x)). With this database, programs can work with a variety of terminals with the same code. Using the termcap database and library functions provides only low level access to the terminal. Changing attributes or colors, parameterized output and optimization must be done by the programmer himself.
- terminfo database
The TERMinal INFOrmation database is based on the termcap database and also describes terminal capabilities, but on a higher level than termcap. Using terminfo, the program can easily change screen attributes, use special keys such as function keys and more. The database can be found in /usr/lib/terminfo/[A-z,0-9]*. Every file describes one terminal.
- curses
Terminfo is a good base to use for terminal handling in a program. The (BSD-)CURSES library gives you high level access to the terminal and is based on the terminfo database. Curses allows you to open and manipulate windows on the screen, provides a complete set of input and output functions, and can alter video attributes in a terminal independent manner on more than 150 terminals. The curses library can be found in /usr/lib/libcurses.a. This is the BSD version of curses.
- ncurses
Ncurses is the next improvement. In version 1.8.6 it should be compatible with AT&T curses as defined in SYSVR4 and has some extensions such as color manipulation, special optimization for output, terminal specific optimizations, and more. It has been tested on a lot of systems such as Sun-OS, HP and Linux. I recommend using ncurses instead of the others. On SYSV Unix systems (such as Sun's Solaris) there should exist a curses library with the same functionality as ncurses (actually the solaris curses has some more functions and mouse support).
In the following sections I will describe how to use the different packages to access a terminal. With Linux we have the GNU-version of termcap and we can use ncurses instead of curses.
Next: 8.1 I/O Function in Up: e Previous: 7.2 Programming a sound
Converted on:
Fri Mar 29 14:43:04 EST 1996