In the following description, these data type representations are assumed:
An 8-bit quantity. Synonymous with "octet".
A single byte that's either 0 (false) or 1 (true).
Two bytes representing a 16-bit integer in little endian format. The value must be either a non-negative 15-bit value or the special value -1 (stored as
- string data
Character data is stored as NUL-terminated ASCII strings.
A terminfo file starts with a 12 byte header, consisting of 6 ints:
The number 282 (stored in the file as
The size (in bytes) of the name section.
The number of entries in the bool section.
The number of entries in the num section.
The number of entries in the string section.
The size (in bytes) of the string table.
To make sense of the stored data,
you need to know that there is a fixed number of bool/num/string capabilities each,
and that they have a fixed order.
So if a terminfo file wanted to set the third num capability to 4 and leave the first/second num capabilities unspecified,
it would fill its num section with
TODO: Document the names/order of all capabilities.
- The name section
The name section contains a (NUL-terminated) string with one or more parts separated by
|(pipe). The first part is the primary name of the terminal; the last part is a human-readable description. The middle parts should be other names for the terminal. All parts except for the last should contain lowercase letters only.
- The bool section
The bool section consists of BOOL_COUNT bytes, each representing a boolean value.
- Interlude: padding
If NAME_SIZE + BOOL_COUNT is not an even number, a padding byte is inserted here.
- The num section
The num section consists of NUM_COUNT ints. A value of -1 indicates that the corresponding numeric capability is missing.
- The string section
The string section consists of STRING_COUNT ints. A value of -1 indicates that the corresponding string capability is missing. Any other value is an offset from the beginning of the string table.
- The string table
The string table consists of TABLE_SIZE bytes. It stores the data for string capabilities. Each entry in the string section specifies the byte at which the corresponding string starts; the end of a string is marked by a NUL byte.
In addition to the standard capabilities described above, ncurses supports user-defined capabilities with arbitrary names. If any of these are present, instead of the end of the file an extended header follows after the main data.
The extended header consists of possibly a padding byte and 5 ints.
- Interlude: padding
If the standard part of the file contains an odd number of bytes, a padding byte is inserted here.
The number of entries in the extended bool section.
The number of entries in the extended num section.
The number of entries in the extended string section.
The number of entries in the string table.
NB: The ncurses code for writing terminfo files calculates this as EXT_BOOL_COUNT + EXT_NUM_COUNT + EXT_STRING_COUNT + EXT_STRING_COUNT (one entry for each capability name plus one entry for each string value). The ncurses code for reading terminfo files ignores this field.
NB: term(5) (part of ncurses) misdocuments this field as "size of the extended string table in bytes". This is wrong.
The size (in bytes) of the extended string table.
NB: term(5) (part of ncurses) misdocuments this field as "last offset of the extended string table". This is wrong.
- The extended bool section
The extended bool section consists of EXT_BOOL_COUNT bytes, each representing a boolean value.
- Interlude: padding
If EXT_BOOL_COUNT is not an even number, a padding byte is inserted here.
- The extended num section
The extended num section consists of EXT_NUM_COUNT ints.
- The extended string section
The extended string section consists of EXT_STRING_COUNT ints that are offsets from the beginning of the extended string table.
- The extended string section 2: Electric boogaloo
The extended string section 2 consists of EXT_BOOL_COUNT + EXT_NUM_COUNT + EXT_STRING_COUNT ints that are offsets from the middle (see below) of the extended string table.
- The extended string table
The extended string table consists of EXT_TABLE_SIZE bytes. The first half of the extended string table stores the data for extended string capabilities. The second half of the string table stores the names of all extended capabilities.
The start of the second half (what I call the "middle") must be computed dynamically from the number (EXT_STRING_COUNT) and size of the strings in the first half.