Next: 8.1 I/O Function in Up: e Previous: 7.2 Programming a sound

# 8 Character Cell Graphics

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.

- 8.1 I/O Function in libc
  - 8.1.1 Formatted Output
  - 8.1.2 Formatted Input
- 8.2 The Termcap Library
  - 8.2.1 Introduction
  - 8.2.2 Find a Terminal Description
  - 8.2.3 Look at a Terminal Description
  - 8.2.4 Termcap Capabilities
    - Boolean Capabilities
    - Numeric Capabilities
    - String Capabilities
- 8.3 Ncurses - Introduction
- 8.4 Initializing
- 8.5 Windows
- 8.6 Output
  - 8.6.1 Formatted Output
  - 8.6.2 Insert Characters/Lines
  - 8.6.3 Delete Characters/Lines
  - 8.6.4 Boxes and Lines
  - 8.6.5 Background Character
- 8.7 Input
  - 8.7.1 Formated Input
- 8.8 Options
  - Output Options
  - 8.8.1 Input Options
  - 8.8.2 Terminal Attributes
  - 8.8.3 Use Options
- 8.9 Clear Window and Lines
- 8.10 Updating the Terminal
- 8.11 Video Attributes and Color
- 8.12 Cursor and Window Coordinates
- 8.13 Scrolling
- 8.14 Pads
- 8.15 Soft-labels
- 8.16 Miscellaneous
- 8.17 Low-level Access
- 8.18 Screen Dump
- 8.19 Termcap Emulation
- 8.20 Terminfo Functions
- 8.21 Debug Function
- 8.22 Terminfo Capabilities
  - 8.22.1 Boolean Capabilities
  - 8.22.2 Numbers
  - 8.22.3 Strings
- 8.23 [N]Curses Function Overview

Next: 8.1 I/O Function in Up: e Previous: 7.2 Programming a sound