Next: , Previous: , Up: Style   [Contents][Index]


12.3.7 Color output

In the design of FWEB, provision has been made for writing various messages to the terminal in color—e.g., serious error messages might appear in red. This feature was motivated by the color ls of Linux. It is installed automatically if the termcap library is present.

Messages output from FWEB are ranked according to an internal message-type table; each type can be associated with a color that can be changed in the style file. Presently, the message types (hopefully self-explanatory) are

ordinary
program_name
mod_name
info
warning
error
fatal
mod_num
line_num
in_file
include_file
out_file
timing

The associated style-file parameters are the above names prefaced by ‘color.’—e.g., color.warning. Each of those has a default value, such as color.error = "red". Those defaults can be displayed by saying ‘ftangle -Zcolor’.

What the color actually means in practice depends on the color mode, set by the ‘-C’ option (see -C_). That selects one of several primitive palettes, as follows:

0

No color; ordinary black-and-white output. This is the default (and the mode used when the termcap library is not present).

1

ANSI color. With a color terminal that supports ANSI color escape sequences, one has available the following colors: "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", and "default". These are displayed with bold attribute (that is, bright, not dim). ‘"default"’ stands for the usual black on white background, or vice versa.

2

Bilevel. This is for terminals that don’t support true color, but do support a double-bright mode and reverse video. Colors are mapped onto various combinations of those two display attributes, according to an internally defined scheme. For example, "red" is mapped onto the pair of escape sequences ‘md’, ‘mr’ (double-bright mode in reverse video).

3

Trilevel. As above, but adds underlining capability.

4

User-defined colors. This implements a minimal set of defaults. It is intended that the user add definitions in the style file to override those defaults.

The mechanism is intended to work with systems that support the termcap library. The terminal is controlled by writing appropriate escape sequences to it. The style-file parameters that store the escape sequences are the color name preceded by ‘Color.’ (note the upper case ‘C’)—e.g., ‘Color.red’. For cases like reverse video (standard termcap abbreviation ‘mr’), the escape sequences are determined by querying the termcap database (usually /etc/termcap) through the termcap library functions. For ANSI color (color mode = 1), ANSI escape sequences are hard-coded into FWEB. One can see the escape sequences FWEB assigns to colors by saying ‘ftangle -ZColor’.

For any non-zero color mode, one can override FWEB’s default choices for color mappings and escape sequences by redefining one or more of the Color parameters in the style file. The escape sequences can either be specified in raw form—e.g., for color mode = 1, a default is Color.red = "\e[01;31m"—or in the form of a sequence of two-character abbreviations that are defined in the termcap documentation—e.g., for modes 2 and 3, the default is Color.red = "mdmr". (When one displays that with the ‘-Z’ option, FWEB will display the actual escape sequences that it determines from the termcap database, not the abbreviations. For both input and output, note that one may use the non-ANSI escape sequence ‘\e’ to represent the escape character ‘\033’.)

When one says ‘-ZColor’, for color modes 1–3 all of the parameters are listed as modified, even if the user redefines none. That occurs because the defaults are overwritten internally when the color mode is set.

FWEB’s configuration script attempts to determine whether the termcap library is present; if not, they link in dummy termcap routines (termcap0.web). To override this behavior, change the appropriate lines in defaults.mk, produced by the command ./configure.

Color message output is not fully debugged (it’s a frill, after all), so some messages that should reasonably be colored may not be so in the present release.


Next: , Previous: , Up: Style   [Contents][Index]