Chapter 21. The Linux Console

The Linux console normally imitates a serial terminal. By writing special character sequences to the console device, you control all aspects of the screen presentation. You will usually use S-Lang, curses, or some other screen-drawing library to draw to the screen; they use these escape sequences. The console can also be read and modified through an alternative full-screen interface, which is particularly useful for some specialized programs.

DOS programmers introduced for the first time to Linux programming often are dismayed to find that writing characters to the screen is not a simple matter of initializing a pointer to the address of the screen in memory and writing blindly through it. Some complain loudly about this “backwards” system that forces them to pretend that they are writing to a serial terminal, writing escape sequences in between the characters that are written to the screen to control cursor movement, color, screen clearing, and so on.

There are several good reasons to treat the console as a fancy serial terminal. Not the least is that when the program is being run on a serial terminal, it still works. More important—in these Internet-conscious times—the program runs correctly across networks and—in these GUI-conscious times—the program runs correctly in a terminal emulator window under X or any other GUI. Furthermore, programs that are run remotely, either via a network or a serial connection, display properly on your console.

Furthermore, you will find that the escape codes are a reasonable low-level interface to the screen, and they are a good base on which to build higher-level primitives, such as curses, documented in Programming with curses [Strang, 1991A]. This is no accident; serial terminals are a venerable technology, fine-tuned over the years in response to programmers’ real needs. The Linux console is based on the most popular family of serial terminals, the descendants of the DEC VT100.

Most escape sequences use the ANSI escape character, which has no convenient printed representation. We follow the termcap and terminfo libraries in using ^[ to denote the ANSI escape character; be aware when reading them that they sometimes refer to the same character as E. As elsewhere in this book, as well as in termcap and terminfo, ^C indicates the Control-C character.

Capability Databases

The actions controlled by these escape sequences are often called capabilities. Some escape sequences are shared among many terminals, and many of those sequences are specified in the ANSI X3.64-1979 standard. Nearly all color-capable terminals use the same sequences to choose colors to display. However, many terminals have wildly different escape sequences. For instance, on a Wyse 30 terminal, pressing F1 sends the sequence ^A@ , whereas pressing F1 on your Linux console sends the sequence ^[[[A. Similarly, to move the cursor up on a Wyse 30, you send it a ^K character; to move the cursor up on the Linux console, send the ^[[A sequence. To write a program that can work on either terminal, you clearly need a way to abstract these differences, which would allow you to program with the capabilities rather than the raw character sequences.

The most common programming library that provides this abstraction is called curses,[1] documented in Programming with curses [Strang, 1991A]. It has two important conceptual levels. The first level provides functions that (generally speaking) send one escape sequence to accomplish one action, such as move the cursor up, move it down, scroll the screen, and so on. The second level provides a concept of “windows": independent screen areas that can be manipulated separately, with curses quietly figuring out the shortest character sequences to send to effect the changes you request.

The curses library determines which sequences to send to the terminal by consulting a database that, for each terminal, maps capability names to the strings that need to be sent.

Linux, like all modern Unix systems, provides two databases that describe terminals in terms of the capabilities they possess and which escape sequences map to which capabilities. The older database is called termcap (short for terminal capabilities) and is kept in one large ASCII flat file called /etc/termcap. This file has become unwieldy; it has grown to approximately half a megabyte. The newer database is called terminfo (short for terminal information) and is kept in many binary files, one per terminal, normally in subdirectories of the /usr/lib/terminfo directory.

Within each database, the capability information for each terminal is indexed by one or more unique names. Both databases use the same name for the same terminal. For instance, the Linux console is called linux in both termcap and terminfo. You tell programs which terminal entry to use by setting the TERM environment variable. When writing programs that use termcap and terminfo, you rarely need to look at the TERM environment variable; usually, the low-level libraries for accessing the termcap or terminfo databases automatically take care of that.

However, if you wish to do Linux-specific optimizations, especially if you want to use some of Linux’s unusual capabilities that are not described in the capability databases, you can check the TERM environment variable with code like this:

if (!strcmp("linux", getenv("TERM"))) {
    /* should be a Linux console */
} else {
    /* handle as a normal serial terminal */
}

Also, if you wish to write programs in programming languages without easy access to curses or some other terminal abstraction library, you may find it convenient to use this documentation.

Of course, that your terminal type is linux does not guarantee that your program is running on a local terminal. If the terminal type is linux, you know you have access to the escape sequences documented in this chapter, but you do not know if you have access to the vcs devices (documented later in this chapter) or ioctl() s. POSIX specifies a ttyname() function that you can use to find the name of the device file for the controlling terminal. On a Linux system, the virtual consoles are named /dev/ttyn for n between 1 and 63 (/dev/tty0 is always the current console).

Complete documentation for the termcap and terminfo systems is available in termcap & terminfo [Strang, 1991B]. Eric Raymond currently maintains the termcap and terminfo databases, which he makes available via the Web at http://www.ccil.org/~esr/terminfo/ The source code to ncurses (new curses, the implementation of curses used on Linux) includes an introduction to curses programming in the misc/ncurses-intro.html file.

Glyphs, Characters, and Maps

When you write a character to any terminal, several steps of translation may happen. The value written to the terminal is the character number, or character code. That character code is not enough to determine what to display on the screen, however. The shape depends on what font is being used. The character code 97 may be printed as an a in a font designed for rendering Latin-based languages, but might be rendered as an in a font designed for rendering Greek or mathematics. The shape that is displayed is called a glyph. The translation from character codes to glyphs is called a map.

Linux Console Capabilities

The Linux console,[2] like most terminals, is modal: Its response to data depends on what mode it is in. By default, it prints on the screen the characters you send to it unless it receives an escape or control character. A control character simply causes some control action to be taken, but the next character is read normally; there is no change in processing mode. An escape character signals the beginning of an escape sequence and changes the processing mode to escape mode.

For example, consider the following C string:

"this is a line
a 33[1mbold33[0m word
"

The console processes the string in the following sequence:

  1. Starting from the current cursor position, the console prints the words “this is a line“.

  2. It encounters the linefeed ( ) control character, so (because Linux and Unix traditionally operate in a mode in which a linefeed signals a carriage return, as well) it moves the cursor to the beginning of the next line, scrolling the whole display up one line if the cursor was already on the bottom line.

  3. It displays the string “a ” at the beginning of that line.

  4. It encounters the escape character, “33”, and moves into escape mode.

  5. It reads the “[”character, and moves into Command Sequence Introduction (CSI) mode.

  6. In CSI mode, it reads a series of ASCII-coded decimal numbers separated by “;”, which are called parameters, until a letter is encountered. The letter determines what action to take, modified by the data in the parameters. In this case, there is one parameter, “1”, and the letter “m” means that the parameter is used to determine character rendition; the “1” sets the bold attribute on.

  7. It prints the string “bold” in a bold rendition.

  8. Another character rendition sequence follows, which resets all attributes to their default, so it prints “ word” in a normal rendition.

  9. Finally, it encounters and processes another newline.

So, assuming that the cursor was at the beginning of a line to start with, the output from the entire string will look something like this:

this is a line
a bold word

Control Characters

The console reads control characters immediately, acts on them, and then continues to read characters in normal mode.

In termcap and terminfo files and documentation, control characters are represented by ^c. We use that convention often in this book, because it will be more generally useful to you than octal C escape sequences. To find the numeric value of a control character, some systems provide a CTRL() macro in <termios.h>, but it is not standard on all systems. Instead, we provide our own version, CTRLCHAR():

#define CTRLCHAR(ch) ((ch)&0x1F)

It is used like this:

if (c == CTRLCHAR('C')) {
    /* control-C was pressed */
}

The control characters understood by the Linux console are described in Table 21.1. The ^? character is actually '?'+0100, not '?'-0100, so it is not really a control-question-mark, but ^? is the standard name for it anyway. Its value is 0177 (octal), 127 (decimal), 7F (hexadecimal). You will not be able to use the CTRL macro just described to test for it. Instead, use the numeric value 127.

Table 21.1. Console Control Characters

Control Character

ASCII Name

Description

^G

BEL

Sounds a tone

^H

BS

Moves cursor to previous character without overwriting it if the cursor is not in the first column already

^I

HT

Horizontal tab; moves cursor to next tab stop

^J

LF

Line feed; moves cursor to next line, scrolls scrolling region if already at the bottom of the scrolling region

^K

VT

Vertical tab; treated like a line feed

^L

FF

Form feed; treated like a line feed

^M

CR

Carriage return; moves cursor to beginning of current line

^N

SO

Shift out; use alternate (G1) character set to display glyphs, display glyphs for control characters

^O

SI

Shift in; use normal (G0) character set to display glyphs, do not display glyphs for control characters

^X

CAN

Cancels any escape sequence in progress

^Z

SUB

Cancels any escape sequence in progress

^[

ESC

ESCape; begins an escape sequence

^?

DEL

Ignored

ALT-^[

n/a

Introduces a command sequence, described later

Note that the effect of some of these codes depends on the tty settings. Although the console itself is precisely documented here, the tty settings may alter what characters are sent. For instance, sending a ^J (LF) usually causes the tty layer also to send a ^M (CR), and ^? (DEL) can be set to send ^H (BS) instead.

The ALT-^[ character is not an ASCII character at all. It is an ESC character with the eighth bit set—ASCII specifies only 7-bit characters. You can use it as a shortcut for entering the CSI sequence, but we recommend that you avoid it because it requires an 8-bit-clean communications link, which might keep your program from running remotely on another Linux system connected, perhaps, by a serial link that transmits only seven bits out of every byte.

For more information on the ASCII characters, see the ascii(7) online manual page. Similarly, the iso_8859_1(7) manual page covers the 8-bit ISO Latin 1 character set (more properly, ISO 8859 Latin Alphabet number 1); this newer standard is becoming the de facto replacement for ASCII, which is now officially called ISO 646-IRV.

Escape Sequences

There are several distinct types of escape sequences. The simplest type of escape sequence consists of the escape character (^[) followed by a single command character. (Although the escape character is represented in C strings as 33, it is represented as ^[ in termcap and terminfo files and documentation.) Five of those single command characters preface more complex escape sequences called command sequences, and the rest cause the console to take simple actions and immediately leave escape mode. The simple escape sequences are documented in Table 21.2

Table 21.2. Console Control Sequences

Escape Sequence

Description

^[M

Moves cursor up one line in current column, back-scrolling screen if necessary (reverse line feed)

^[D

Moves cursor down one line in current column, scrolling screen if necessary (line feed)

^[E

Carriage return and line feed

^[H

Sets tab stop in current column

^[7

Stores cursor position and attributes

^[8

Restores cursor position and attributes

^[>

Puts keypad in numeric mode (normal)

^[=

Puts keypad in application mode (act like DEC VT102 function keys)

^[c

Resets every terminal setting that can be set through control characters and escape sequences

^[Z

Requests terminal ID. Response is ^[[?6c, saying that the console faithfully emulates a DEC VT102 (it includes a large superset of the DEC VT102’s capabilities)

Storing and restoring the cursor position (^[7 and ^[8) are not done on a stack; if you do two stores in a row, the second stored position overwrites the first stored position. Conversely, after storing the cursor position once, you can restore it as many times as you wish. Each time, the cursor will revert to the same location. When you restore the cursor position, you also restore character rendition attributes, current character set, and character set definitions, all described later in this chapter.

Cursor position is given in terms of a character cell address, an x,y pair of numbers that names one position on the screen. Character cell addresses on most terminals, including the Linux console, do not follow standard computer-science practice of counting from zero. The upper-left character on the screen is the origin and is addressed as character cell 1,1.

Note that control characters may be included in the middle of an escape sequence. For example, ^[^G8 first beeps and then restores the cursor position and attributes. The sequence ^[^X8 simply prints an 8.

Testing Sequences

To test most sequences, you merely need to log into a virtual console and run cat. Type the sequences you wish to test, and watch the results. For ^[, press the Escape key.

Terminal responses to commands such as the ^[Z terminal identification command or the CSIn command documented later show up as escape sequences that disappear in terminal handling. In cases in which you wish to see such a response, you can simply run

cat > /tmp/somefile

Then type the commands, followed by a return and a ^D. Use less, vi, Emacs, or some other program that can handle arbitrary characters to read /tmp/somefile, where you will find the responses directly following the sequences you typed.

Complex Escape Sequences

Five two-character escape sequences are really prefixes to longer, more-complex escape sequences, as shown in Table 21.3. We describe each of these sequences, in turn.

Table 21.3. Complex Console Escape Sequences

Escape Sequence

Description

^[[

Begins a CSI sequence (ALT-^[ is a synonym for this)

^[]

Begins a palette-setting sequence

^[%

Begins a UTF (UTF-8 wide-character Unicode) sequence

^[(

Chooses font mapping for G0 character set

^[)

Chooses font mapping for G1 character set

^[#8

DEC private test sequence; fills screen with E characters

CSI sequences have three or four parts.

  1. ^[[ starts a CSI sequence, putting the terminal in CSI mode.

  2. For the h and l sequences only, you can include a ? character to allow you to set or clear DEC private modes (see page 525).

  3. You may provide up to 16 parameters. Parameters are decimal numbers separated by ; characters. 1;23;45 is a list of three parameters: 1, 23, and 45. (If the ; parameter separator is found after 16 parameters have already been read, the CSI sequence is terminated immediately and the terminal goes into normal mode, printing the rest of the sequence.)

  4. A command character terminates the sequence and determines how to interpret the parameters the terminal has already encountered.

The parameters are usually referred to as par1 through par16. If you do not set a parameter explicitly, its value is automatically set to 0 or 1, depending on what makes the most sense. The CSI command characters are documented in Table 21.4.

Table 21.4. CSI Sequences

Char

Description

h

Sets mode; see page 525

l

Clears mode; see page 525

n

par1 =5

Status report: Terminal responds with ^[[0n, which means “OK”

 

par1 =6

Cursor position report: Terminal responds with ^[[x;yR, where y is relative to the origin rather than the region if origin mode is selected (see Table 21.9)

G or '

Sets cursor horizontal position to column par1

A

Moves cursor vertical position up by par1 rows

B or e

Moves cursor vertical position down by par1 rows

C or a

Moves cursor horizontal position right by par1 columns

D

Moves cursor horizontal position left by par1 columns

E

Moves cursor to beginning of line and down par1 rows (1 by default)

F

Moves cursor to beginning of line and up par1 rows (1 by default)

d

Sets cursor vertical position to row par1

H or f

Sets cursor vertical position to row par1 and horizontal position to column par2 (both default to zero, moving the cursor to the origin)

J

par1=0

Clears from cursor to end of display

 

par1=1

Clears from origin to cursor

 

par1=2

Clears entire display

K

par1=0

Clears from cursor to end of line

 

par1=1

Clears from start of line to cursor

 

par1 =2

Clears entire line

L

Inserts par1 lines above the current line

M

Deletes par1 lines, starting with the current line

P

Deletes par1 characters at the current position, shifting the rest of the line left

c

Responds with ^[[?6c (synonym for ^[Z)

g

par1 =0

Clears tab in current column (default)

 

par1 =3

Clears all tabs

m

Character rendition sequence; see Table 21.7

q

Turns keyboard LED par1 on and others off (0 turns all off)

r

Sets scrolling region (applied only in DEC origin mode; see page 525):

 

par1

First line of region, must be between 1 (default) and par2 -1

 

par2

Last line of region, must be between par1 +1 and bottom line (default)

s

Stores cursor position and attributes (synonym for ^[7)

u

Restores cursor position and attributes (synonym for ^[8)

X

Erases up to par1 characters, up to the end of the current line

@

Erases up to par1 characters, up to the end of the current line

]

setterm sequences; see Table 21.10

Several sequences take arguments describing colors; they all use the same mapping from numbers to colors, documented in Table 21.5. Sequences that describe background colors accept only color numbers between 0 and 7; sequences that describe foreground colors accept numbers between 8 and 15 that describe bold or bright colors.

Table 21.5. Color Codes

N

Color

N

Bright Color

0

Black

8

Dark gray

1

Red

9

Bright red

2

Green

10

Bright green

3

Brown

11

Yellow

4

Blue

12

Bright blue

5

Magenta

13

Bright magenta

6

Cyan

14

Bright cyan

7

Gray

15

White

These colors are actually offsets into a table—the color names in the table describe the default colors stored at those offsets. However, you can change those colors with a palette-setting sequence; the ^[]P sequence sets an individual palette entry, and the ^[]R sequence resets the palette to the system default palette. Palette entries are defined by seven hexadecimal digits that follow ^[]P, as documented in Table 21.6. So for each palette entry, you can provide a 24-bit color definition with eight bits for each color.

Table 21.6. Color Palette Components

Digit Number

Defines

  

1

Palette entry to redefine

  

2*16+3

Value of red component of palette entry

  

4*16+5

Value of green component of palette entry

  

6*16+7

Value of blue component of palette entry

  

The character rendition sequences denoted by the CSI m command may have up to 16 parameters, documented in Table 21.7, in any order. They are applied to the terminal in the order in which they are given, so if 0 to set the default rendition is followed by 1 to set bold, the result is a bold—but not blinking, reverse video, or underlined—character, regardless of the previous rendition settings.

Table 21.7. Character Rendition Parameters

par

Description

0

Default rendition: normal intensity, no underline, not reverse video, no blinking, and the default color scheme (white on black unless set otherwise by the setterm store sequence ^[[]8)

1

Bold intensity

2

Dim intensity

4

Enables underline

5

Enables blink

7

Enables reverse video

10

Selects primary font (ISO latin 1), does not display control characters, unsets bit 8 on output

11

Selects alternate font (IBM Codepage 437), displays control characters as graphics, unsets bit 8 on output

12

Selects alternate font (IBM Codepage 437), displays control characters as graphics, leaves bit 8 set on output

21 22

Normal intensity

24

Disables underline

25

Disables blink

27

Disables reverse video

30 - 37

Sets foreground color to par ||30; see Table 21.5

38

Enables underline and uses default foreground color

39

Disables underline and uses default foreground color

40 - 47

Sets background color to par ||40; see Table 21.5

49

Uses default background color

Related somewhat to the character rendition sequences are the mode sequences. There are two types of modes: ANSI modes and DEC private modes. The CSI h sequence sets ANSI modes, documented in Table 21.8, and the CSI l sequence clears them. More than one parameter can be included in a sequence. The CSI ?h sequence sets DEC private modes, documented in Table 21.9, and the CSI ?l sequence clears them. Again, more than one parameter can be included.

Table 21.8. ANSI Modes

par

Description

3

Displays control characters

4

Insert mode

20

CRLF mode (produces a carriage return when a linefeed is received)

Table 21.9. DEC Private Modes

par

Description

1

Cursor keys as application keys; in application mode, they are prefixed with ^[O instead of the usual ^[[

3

Unimplemented; may switch between 80- and 132-column mode in the future

5

Sets entire screen in inverse video

6

Sets DEC origin mode, in which scrolling regions are honored, and goes to the origin (of the current scrolling region, if any)

7

Sets autowrap mode (on by default), in which characters that would go beyond the screen cause an automatic CRLF. When autowrap mode is turned off, extra characters overwrite the right-most character on the current line

8

Sets keyboard auto-repeat mode (on by default)

9

Mouse reporting mode 1 (support may be provided by an external program)

25

Makes cursor visible (on by default)

1000

Mouse reporting mode 2 (support may be provided by an external program)

The setterm sequences are a set of CSI sequences with the command character ]. They are documented in Table 21.10.

Table 21.10. Console setterm Sequences

par

Description

1

Sets color to use to represent underline attribute to par2

2

Sets color to use to represent dim attribute to par2

8

Stores current setterm attributes as the defaults, making them the default character rendition attributes

9

Sets screen-blank interval to par2 minutes, but no more than 60 minutes. par2 set to 0 disables screen-blank

10

Sets the console bell frequency to par2 Hz or to the default pitch if par2 is unspecified

11

Sets the console bell duration to par2 milliseconds if par2 is spec-ified and is less than 2000. If par2 is not specified, resets the duration to the default

12

If console par2 is allocated, makes console par2 active (see Chapter 20)

13

Unblanks the screen

14

Sets VESA power-down interval to par2 minutes, but no more than 60 minutes. par2 set to 0 disables VESA power down

There is more to conversing with the console than telling it what to display; you also must recognize key sequences and know which keys they are attached to—and although some of them are specified in the terminfo database, others are not. To make life even more interesting, the keyboard is modal. In application mode, the cursor keys produce different codes. As shown in Table 21.9, they are prefixed with ^[O instead of ^[[. This is to support legacy applications that assume that they are talking to DEC terminals.

The key sequences are documented in Table 21.11. Note that the function-key numbering has gaps and that it is designed so that people without F11 and F12 keys are not handicapped.

Table 21.11. Function-Key Encodings

Key Sequence

Key(s)

^[[[A

F1

^[[[B

F2

^[[[C

F3

^[[[D

F4

^[[[E

F5

^[[17~

F6

^[[18~

F7

^[[19~

F8

^[[20~

F9

^[[21~

F10

^[[23~

F11, Shift-F1, Shift-F11

^[[24~

F12, Shift-F2, Shift-F11

^[[25~

Shift-F3

^[[26~

Shift-F4

^[[28~

Shift-F5

^[[29~

Shift-F6

^[[31~

Shift-F7

^[[32~

Shift-F8

^[[33~

Shift-F9

^[[34~

Shift-F10

^[[A

Up arrow

^[[D

Left arrow

^[[B

Down arrow

^[[C

Right arrow

^[[1~

Home

^[[2~

Insert

^[[3~

Delete

^[[4~

End

^[[5~

Page Up

^[[6~

Page Down

Direct Screen Writing

There are some cases in which being able to write characters to the screen is simply insufficient, partially because it is impossible to determine the current state of the screen. Although standard Unix practice is to ignore the state of the screen—to set it up as you need it, make changes to it as you have changes to make, and to redraw it completely any time the user requests it (usually by pressing ^L)—you may have other applications in mind.

In particular, screen capture and restore programs and functions need access to the current contents of the screen. Linux provides this through two interfaces. One provides only the text contents of the screen, and one contains attributes (color and so forth), as well.

The simple text device is called vcs, which presumably stands for virtual console screen.[3] The /dev/vcs0 device when read produces the contents of the current virtual console as it is being viewed at the time it is read. If the screen is currently scrolled back (the Control-PageUp and Control-PageDown keys are set up to control console scrolling by default), /dev/vcs0 contains the scrolled-back contents that are being viewed. The rest of the vcs devices, /dev/vcs n, each represent the current state of the virtual console n, normally accessed through /dev/ttyn.

When you read /dev/vcs*, you are given no indication of new lines or of console size other than an EOF at the end of the screen. If you read 2,000 bytes and then receive an EOF, there is no indication whether the screen is 80 columns and 25 lines or 40 columns and 50 lines. No newline characters are produced to mark the ends of lines, and every empty character cell, whether or not it was ever written to, is denoted by a space character. There are several popular screen configurations, and there is no guarantee that each of them has a unique number of lines and columns. The vcs device provides an easy way for a savvy sysadmin or developer to see what is on any virtual console, but it is not very useful from a programmer’s standpoint, at least alone.

One useful way to use vcs is from within X. XFree86, by default, starts the X server on the first free virtual console, not on the console that the program was started from. If you start XFree86 from virtual console 1, you do not need to change back to virtual console 1 to see the detection messages that XFree86 left on the screen; bring up a terminal window the same size as the console (normally 80 columns by 25 lines), become superuser (in order to gain access to the vcs device), and run cat /dev/vcs1. The contents of the first virtual console will fill your terminal window.

In order to write reliable programs, however, you need some basic knowledge about the state of the screen that a vcs device does not provide

  • Colors

  • Other attributes (such as blinking)

  • Current cursor position

  • Screen configuration (number of rows and columns)

The vcsa device (which presumably stands for virtual console screen with attributes) provides all this. The first four bytes of /dev/vcsan (for the same n as vcs devices) contain a header that gives the current cursor position and screen configuration. The first byte contains the number of rows, the second the number of columns, the third the cursor’s current column, and the fourth the cursor’s current row. The rest of the file contains alternating bytes that represent the text and text attribute bytes of the console in question.

So, if you need to know only the size of the console and its textual contents, you can read the first two bytes of the appropriate vcsa device and from then on use only the vcs device. If you want to set the current cursor position, write to the third and fourth bytes of the vcsa device (the first two bytes are read-only, so the first two characters are placeholders; we prefer to use spaces or some other similar character to make this more obvious). As an example, to move the cursor on the fourth virtual console to the eighth row and the twentieth column (counting from zero):

echo -n -e '..2307' > /dev/vcsa4

The -n keeps echo from adding a newline character to the end, and the -e makes it interpret escape codes, so that nnn is interpreted as octal character nnn.

The attributes and character contents are represented as alternating bytes, the first containing the character and the second containing the attributes to apply to the character. The attribute byte is normally defined like the attribute byte used on VGA hardware. Other kinds of hardware, including the TGA cards used on many Linux/Alpha machines and the SPARC console driver, emulate the VGA attribute handling. On video hardware without color support but with underline support, it can be read slightly differently; it is designed in such a way that you can pretend that it is all VGA hardware, and all other hardware will behave somewhat reasonably.

For each attribute byte, the bits are interpreted as documented in Table 21.12. That is the VGA representation; some color hardware replaces blink by a bright background. The monochrome representation uses bit 0 of the foreground color to indicate underline.

Table 21.12. Attributes

Bit(s)

Effect

7

Blink

6-4

Background

3

Bold

2-0

Foreground



[1] The curses library is defined by X/Open. The implementation included in Linux is currently base-level conformant with X/Open XSI Curses.

[2] This description owes a considerable amount of organization to an excellent usenet post to the comp.os.linux.announce newsgroup by Peter Jones on September 30, 1995.

[3] This section belongs logically to Chapter 20 because it is related to virtual consoles, but it belongs in this chapter in a practical sense—you would not know to look in Chapter 20 unless you did not need to read this book in the first place.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.124.135