terminfo(5)

๐ŸŒธ NAME ๐ŸŒธ

terminfo โ€” terminal capability database

Okay so you're reading terminfo(5), bestie โ€” it lives in the File formats section of the manual, and it's literally the terminal capability database. Iconic.

โœจ SYNOPSIS โœจ

/usr/share/terminfo/*/*

๐Ÿ’– DESCRIPTION ๐Ÿ’–

Terminfo is a database describing terminals. It's used by screen-oriented programs like nvi(1), lynx(1), mutt(1), and other curses applications, using high-level calls to libraries such as curses(3X). It's also used via low-level calls by non-curses applications which may be screen-oriented (such as clear(1)) or non-screen (such as tabs(1)). No cap, it gets around.

Terminfo describes terminals by giving a set of capabilities which they have, by specifying how to perform screen operations, and by specifying padding requirements and initialization sequences. It's giving terminal rรฉsumรฉ.

This document describes ncurses version 6.6 (patch 20260516). Periodt.


๐ŸŽ€ terminfo Entry Syntax ๐ŸŽ€

Entries in terminfo consist of a sequence of fields:

  • Each field ends with a comma , โ€” embedded commas may be escaped with a backslash or written as \054. iykyk
  • White space between fields is ignored.
  • The first field in a terminfo entry begins in the first column.
  • Newlines and leading whitespace (spaces or tabs) may be used for formatting entries for readability. These are removed from parsed entries.

The infocmp -f and -W options rely on this to format if-then-else expressions, or to enforce maximum line-width. The resulting formatted terminal description can be read by tic. slay, formatting queen.

  • The first field for each terminal gives the names which are known for the terminal, separated by | characters.

The first name given is the most common abbreviation for the terminal (its primary name), the last name given should be a long name fully identifying the terminal (see longname(3X)), and all others are treated as synonyms (aliases) for the primary terminal name.

X/Open Curses advises that all names but the last should be in lower case and contain no blanks; the last name may well contain upper case and blanks for readability.

This implementation is not so strict; it allows mixed case in the primary name and aliases. If the last name has no embedded blanks, it allows that to be both an alias and a verbose name โ€” but will warn about this ambiguity. not me being flexible but also side-eyeing you.

  • Lines beginning with a # in the first column are treated as comments.

While comment lines are valid at any point, the output of captoinfo and infotocap (aliases for tic) will move comments so they occur only between entries.

Terminal names (except for the last, verbose entry) should be chosen using the following conventions. The particular piece of hardware making up the terminal should have a root name, thus hp2621. This name should not contain hyphens. Modes that the hardware can be in, or user preferences, should be indicated by appending a hyphen and a mode suffix. Thus, a vt100 in 132-column mode would be vt100-w. The following suffixes should be used where possible:

  • -nn โ€” example aaa-60 โ€” Number of lines on the screen
  • -np โ€” example c100-4p โ€” Number of pages of memory
  • -am โ€” example vt100-am โ€” With automargins (usually the default)
  • -m โ€” example ansi-m โ€” Mono mode; suppress color
  • -mc โ€” example wy30-mc โ€” Magic cookie; spaces when highlighting
  • -na โ€” example c100-na โ€” No arrow keys (leave them in local)
  • -nam โ€” example vt100-nam โ€” Without automatic margins
  • -nl โ€” example hp2621-nl โ€” No status line
  • -ns โ€” example hp2626-ns โ€” No status line
  • -rv โ€” example c100-rv โ€” Reverse video
  • -s โ€” example vt100-s โ€” Enable status line
  • -vb โ€” example wy370-vb โ€” Use visible bell instead of beep
  • -w โ€” example vt100-w โ€” Wide mode (> 80 columns, usually 132)

For more on terminal naming conventions, see the term(7) manual page. go read it, bestie.

๐Ÿฆ‹ terminfo Capabilities Syntax ๐Ÿฆ‹

The terminfo entry consists of several capabilities, i.e., features that the terminal has, or methods for exercising the terminal's features. main character capabilities.

After the first field (giving the name(s) of the terminal entry), there should be one or more capability fields. These are Boolean, numeric or string names with corresponding values:

  • Boolean capabilities are true when present, false when absent. There is no explicit value for Boolean capabilities.
  • Numeric capabilities have a # following the name, then an unsigned decimal integer value.
  • String capabilities have a = following the name, then a string of characters making up the capability value.

String capabilities can be split into multiple lines, just as the fields comprising a terminal entry can be split into multiple lines. While blanks between fields are ignored, blanks embedded within a string value are retained, except for leading blanks on a line.

Any capability can be canceled, i.e., suppressed from the terminal entry, by following its name with @ rather than a capability value. bye, capability.

๐ŸŒˆ Similar Terminals ๐ŸŒˆ

If there are two very similar terminals, one (the variant) can be defined as being just like the other (the base) with certain exceptions. In the definition of the variant, the string capability use can be given with the name of the base terminal:

  • The capabilities given before use override those in the base type named by use.
  • If there are multiple use capabilities, they are merged in reverse order. That is, the rightmost use reference is processed first, then the one to its left, and so forth.
  • Capabilities given explicitly in the entry override those brought in by use references.

A capability can be canceled by placing xx@ to the left of the use reference that imports it, where xx is the capability. For example, the entry

2621-nl, smkx@, rmkx@, use=2621,

defines a 2621-nl that does not have the smkx or rmkx capabilities, and hence does not turn on the function key labels when in visual mode. This is useful for different modes for a terminal, or for different user preferences. lowkey genius.

An entry included via use can contain canceled capabilities, which have the same effect as if those cancels were inline in the using terminal entry.

๐Ÿ‘‘ Standard Capabilities ๐Ÿ‘‘

Tables of capabilities ncurses recognizes in a terminfo terminal type description and available to terminfo-using code follow.

  • The capability name identifies the symbol by which the programmer using the terminfo API accesses the capability.
  • The TI (terminfo) code is the short name used by a person composing or updating a terminal type entry.

Whenever possible, these codes are the same as or similar to those of the ANSI X3.64-1979 standard (now superseded by ECMA-48, which uses identical or very similar names). Semantics are also intended to match those of the specification.

terminfo codes have no hard length limit, but ncurses maintains an informal one of 5 characters to keep them short and to allow the tabs in the source file Caps to line up nicely. (Some standard codes exceed this limit regardless.)

  • The TC (termcap) code is that used by the corresponding API of ncurses. (Some capabilities are new, and have names that BSD termcap did not originate.)
  • The description field attempts to convey the capability's semantics.

The description field employs a handful of notations.

  • (P) โ€” indicates that padding may be specified.
  • (P*) โ€” indicates that padding may vary in proportion to the number of output lines affected.
  • #i โ€” indicates the ith parameter of a string capability; the programmer should pass the string to tparm(3X) with the parameters listed.

If the description lists no parameters, passing the string to tparm(3X) may produce unexpected behavior, for instance if the string contains percent signs. don't just yeet it into tparm with no params, fr fr.

Okay so before we dive in: each row has, in order, the terminfo short name and the termcap code, and then what it actually does. I'm gonna keep that order, promise. โœจ

๐ŸŽ€ Boolean Capabilities (the yes/no girlies) ๐ŸŽ€

These are the flags โ€” they're either on or they're not, no in-between, no "it's complicated." ๐Ÿ’…

  • auto_left_margin โ€” bw/bw โ€” cub1 wraps from column 0 to last column
  • auto_right_margin โ€” am/am โ€” terminal has automatic margins
  • no_esc_ctlc โ€” xsb/xb โ€” beehive (f1=escape, f2=ctrl C)
  • ceol_standout_glitch โ€” xhp/xs โ€” standout not erased by overwriting (hp)
  • eat_newline_glitch โ€” xenl/xn โ€” newline ignored after 80 cols (concept)
  • erase_overstrike โ€” eo/eo โ€” can erase overstrikes with a blank
  • generic_type โ€” gn/gn โ€” generic line type
  • hard_copy โ€” hc/hc โ€” hardcopy terminal
  • has_meta_key โ€” km/km โ€” Has a meta key (i.e., sets 8th-bit)
  • has_status_line โ€” hs/hs โ€” has extra status line
  • insert_null_glitch โ€” in/in โ€” insert mode distinguishes nulls
  • memory_above โ€” da/da โ€” display may be retained above the screen
  • memory_below โ€” db/db โ€” display may be retained below the screen
  • move_insert_mode โ€” mir/mi โ€” safe to move while in insert mode
  • move_standout_mode โ€” msgr/ms โ€” safe to move while in standout mode
  • over_strike โ€” os/os โ€” terminal can overstrike
  • status_line_esc_ok โ€” eslok/es โ€” escape can be used on the status line
  • dest_tabs_magic_smso โ€” xt/xt โ€” tabs destructive, magic so char (t1061)
  • tilde_glitch โ€” hz/hz โ€” cannot print ~'s (Hazeltine)
  • transparent_underline โ€” ul/ul โ€” underline character overstrikes
  • xon_xoff โ€” xon/xo โ€” terminal uses xon/xoff handshaking
  • needs_xon_xoff โ€” nxon/nx โ€” padding will not work, xon/xoff required
  • prtr_silent โ€” mc5i/5i โ€” printer will not echo on screen
  • hard_cursor โ€” chts/HC โ€” cursor is hard to see
  • non_rev_rmcup โ€” nrrmc/NR โ€” smcup does not reverse rmcup
  • no_pad_char โ€” npc/NP โ€” pad character does not exist
  • non_dest_scroll_region โ€” ndscr/ND โ€” scrolling region is non-destructive
  • can_change โ€” ccc/cc โ€” terminal can re-define existing colors
  • back_color_erase โ€” bce/ut โ€” screen erased with background color
  • hue_lightness_saturation โ€” hls/hl โ€” terminal uses only HLS color notation (Tektronix)
  • col_addr_glitch โ€” xhpa/YA โ€” only positive motion for hpa/mhpa caps
  • cr_cancels_micro_mode โ€” crxm/YB โ€” using cr turns off micro mode
  • has_print_wheel โ€” daisy/YC โ€” printer needs operator to change character set
  • row_addr_glitch โ€” xvpa/YD โ€” only positive motion for vpa/mvpa caps
  • semi_auto_right_margin โ€” sam/YE โ€” printing in last column causes cr
  • cpi_changes_res โ€” cpix/YF โ€” changing character pitch changes resolution
  • lpi_changes_res โ€” lpix/YG โ€” changing line pitch changes resolution

๐Ÿ”ข Numeric Capabilities (the ones with actual numbers) ๐Ÿ”ข

Not flags, bestie โ€” these hold values. Counts, sizes, maximums, all of it. ๐Ÿ“

  • columns โ€” cols/co โ€” number of columns in a line
  • init_tabs โ€” it/it โ€” tabs initially every # spaces
  • lines โ€” lines/li โ€” number of lines on screen or page
  • lines_of_memory โ€” lm/lm โ€” lines of memory if > line. 0 means varies
  • magic_cookie_glitch โ€” xmc/sg โ€” number of blank characters left by smso or rmso
  • padding_baud_rate โ€” pb/pb โ€” lowest baud rate where padding needed
  • virtual_terminal โ€” vt/vt โ€” virtual terminal number (CB/unix)
  • width_status_line โ€” wsl/ws โ€” number of columns in status line
  • num_labels โ€” nlab/Nl โ€” number of labels on screen
  • label_height โ€” lh/lh โ€” rows in each label
  • label_width โ€” lw/lw โ€” columns in each label
  • max_attributes โ€” ma/ma โ€” maximum combined attributes terminal can handle
  • maximum_windows โ€” wnum/MW โ€” maximum number of definable windows
  • max_colors โ€” colors/Co โ€” maximum number of colors on screen
  • max_pairs โ€” pairs/pa โ€” maximum number of color-pairs on the screen
  • no_color_video โ€” ncv/NC โ€” video attributes that cannot be used with colors

๐Ÿ–จ๏ธ The SVr4 printer numerics (the deep lore) ๐Ÿ–จ๏ธ

Real talk: these next ones are in the SVr4.0 term structure, but they're not yet documented in the man page. They showed up along with SVr4's printer support. So likeโ€ฆ they're canon, they just don't have a wiki page yet. ๐Ÿ™ˆ

  • buffer_capacity โ€” bufsz/Ya โ€” numbers of bytes buffered before printing
  • dot_vert_spacing โ€” spinv/Yb โ€” spacing of pins vertically in pins per inch
  • dot_horz_spacing โ€” spinh/Yc โ€” spacing of dots horizontally in dots per inch
  • max_micro_address โ€” maddr/Yd โ€” maximum value in micro_..._address
  • max_micro_jump โ€” mjump/Ye โ€” maximum value in parm_..._micro
  • micro_col_size โ€” mcs/Yf โ€” character step size when in micro mode
  • micro_line_size โ€” mls/Yg โ€” line step size when in micro mode
  • number_of_pins โ€” npins/Yh โ€” numbers of pins in print-head
  • output_res_char โ€” orc/Yi โ€” horizontal resolution in units per line
  • output_res_line โ€” orl/Yj โ€” vertical resolution in units per line
  • output_res_horz_inch โ€” orhi/Yk โ€” horizontal resolution in units per inch
  • output_res_vert_inch โ€” orvi/Yl โ€” vertical resolution in units per inch
  • print_rate โ€” cps/Ym โ€” print rate in characters per second
  • wide_char_size โ€” widcs/Yn โ€” character step size when in double wide mode
  • buttons โ€” btns/BT โ€” number of buttons on mouse
  • bit_image_entwining โ€” bitwin/Yo โ€” number of passes for each bit-image row
  • bit_image_type โ€” bitype/Yp โ€” type of bit-image device

And yes, that's genuinely only the booleans and the numerics โ€” the string caps are still coming, so don't go anywhere. ๐Ÿฆ‹

Okay bestie, the table continues โ€” remember the flow: the name is the long one, then the TI code (the terminfo one) and the TC code (the termcap one), then what it actually does ๐Ÿ’…

  • back_tab (cbt / bt) โ€” back tab (P)
  • bell (bel / bl) โ€” audible signal (bell) (P)
  • carriage_return (cr / cr) โ€” carriage return (P*) (P*)
  • change_scroll_region (csr / cs) โ€” change region to line #1 to line #2 (P)
  • clear_all_tabs (tbc / ct) โ€” clear all tab stops (P)
  • clear_screen (clear / cl) โ€” clear screen and home cursor (P*)
  • clr_eol (el / ce) โ€” clear to end of line (P)
  • clr_eos (ed / cd) โ€” clear to end of screen (P*)
  • column_address (hpa / ch) โ€” horizontal position #1, absolute (P)
  • command_character (cmdch / CC) โ€” terminal settable cmd character in prototype !?
  • cursor_address (cup / cm) โ€” move to row #1 columns #2
  • cursor_down (cud1 / do) โ€” down one line
  • cursor_home (home / ho) โ€” home cursor (if no cup)
  • cursor_invisible (civis / vi) โ€” make cursor invisible
  • cursor_left (cub1 / le) โ€” move left one space
  • cursor_mem_address (mrcup / CM) โ€” memory relative cursor addressing, move to row #1 columns #2
  • cursor_normal (cnorm / ve) โ€” make cursor appear normal (undo civis/cvvis)
  • cursor_right (cuf1 / nd) โ€” non-destructive space (move right one space)
  • cursor_to_ll (ll / ll) โ€” last line, first column (if no cup)
  • cursor_up (cuu1 / up) โ€” up one line
  • cursor_visible (cvvis / vs) โ€” make cursor very visible
  • delete_character (dch1 / dc) โ€” delete character (P*)
  • delete_line (dl1 / dl) โ€” delete line (P*)
  • dis_status_line (dsl / ds) โ€” disable status line
  • down_half_line (hd / hd) โ€” half a line down
  • enter_alt_charset_mode (smacs / as) โ€” start alternate character set (P)
  • enter_blink_mode (blink / mb) โ€” turn on blinking
  • enter_bold_mode (bold / md) โ€” turn on bold (extra bright) mode
  • enter_ca_mode (smcup / ti) โ€” string to start programs using cup
  • enter_delete_mode (smdc / dm) โ€” enter delete mode
  • enter_dim_mode (dim / mh) โ€” turn on half-bright mode
  • enter_insert_mode (smir / im) โ€” enter insert mode
  • enter_secure_mode (invis / mk) โ€” turn on blank mode (characters invisible)
  • enter_protected_mode (prot / mp) โ€” turn on protected mode
  • enter_reverse_mode (rev / mr) โ€” turn on reverse video mode
  • enter_standout_mode (smso / so) โ€” begin standout mode
  • enter_underline_mode (smul / us) โ€” begin underline mode
  • erase_chars (ech / ec) โ€” erase #1 characters (P)
  • exit_alt_charset_mode (rmacs / ae) โ€” end alternate character set (P)
  • exit_attribute_mode (sgr0 / me) โ€” turn off all attributes
  • exit_ca_mode (rmcup / te) โ€” strings to end programs using cup
  • exit_delete_mode (rmdc / ed) โ€” end delete mode
  • exit_insert_mode (rmir / ei) โ€” exit insert mode
  • exit_standout_mode (rmso / se) โ€” exit standout mode
  • exit_underline_mode (rmul / ue) โ€” exit underline mode
  • flash_screen (flash / vb) โ€” visible bell (may not move cursor)
  • form_feed (ff / ff) โ€” hardcopy terminal page eject (P*)
  • from_status_line (fsl / fs) โ€” return from status line
  • init_1string (is1 / i1) โ€” initialization string
  • init_2string (is2 / is) โ€” initialization string
  • init_3string (is3 / i3) โ€” initialization string
  • init_file (if / if) โ€” name of initialization file
  • insert_character (ich1 / ic) โ€” insert character (P)
  • insert_line (il1 / al) โ€” insert line (P*)
  • insert_padding (ip / ip) โ€” insert padding after inserted character

Okay now the keycaps, and this is the part everyone actually cares about because keyboard keys are the whole vibe โŒจ๏ธโœจ

  • key_backspace (kbs / kb) โ€” backspace key
  • key_catab (ktbc / ka) โ€” clear-all-tabs key
  • key_clear (kclr / kC) โ€” clear-screen or erase key
  • key_ctab (kctab / kt) โ€” clear-tab key
  • key_dc (kdch1 / kD) โ€” delete-character key
  • key_dl (kdl1 / kL) โ€” delete-line key
  • key_down (kcud1 / kd) โ€” down-arrow key
  • key_eic (krmir / kM) โ€” sent by rmir or smir in insert mode
  • key_eol (kel / kE) โ€” clear-to-end-of-line key
  • key_eos (ked / kS) โ€” clear-to-end-of-screen key
  • key_f0 (kf0 / k0) โ€” F0 function key
  • key_f1 (kf1 / k1) โ€” F1 function key
  • key_f10 (kf10 / k;) โ€” F10 function key
  • key_f2 (kf2 / k2) โ€” F2 function key
  • key_f3 (kf3 / k3) โ€” F3 function key
  • key_f4 (kf4 / k4) โ€” F4 function key
  • key_f5 (kf5 / k5) โ€” F5 function key
  • key_f6 (kf6 / k6) โ€” F6 function key
  • key_f7 (kf7 / k7) โ€” F7 function key
  • key_f8 (kf8 / k8) โ€” F8 function key
  • key_f9 (kf9 / k9) โ€” F9 function key
  • key_home (khome / kh) โ€” home key
  • key_ic (kich1 / kI) โ€” insert-character key
  • key_il (kil1 / kA) โ€” insert-line key
  • key_left (kcub1 / kl) โ€” left-arrow key
  • key_ll (kll / kH) โ€” lower-left key (home down)
  • key_npage (knp / kN) โ€” next-page key
  • key_ppage (kpp / kP) โ€” previous-page key
  • key_right (kcuf1 / kr) โ€” right-arrow key
  • key_sf (kind / kF) โ€” scroll-forward key
  • key_sr (kri / kR) โ€” scroll-backward key
  • key_stab (khts / kT) โ€” set-tab key
  • key_up (kcuu1 / ku) โ€” up-arrow key
  • keypad_local (rmkx / ke) โ€” leave keypad transmit mode
  • keypad_xmit (smkx / ks) โ€” enter keypad transmit mode

And the label caps, which are genuinely so niche and I love that they're documented ๐ŸŽ€

  • lab_f0 (lf0 / l0) โ€” label on function key f0 if not f0
  • lab_f1 (lf1 / l1) โ€” label on function key f1 if not f1
  • lab_f10 (lf10 / la) โ€” label on function key f10 if not f10
  • lab_f2 (lf2 / l2) โ€” label on function key f2 if not f2
  • lab_f3 (lf3 / l3) โ€” label on function key f3 if not f3
  • lab_f4 (lf4 / l4) โ€” label on function key f4 if not f4
  • lab_f5 (lf5 / l5) โ€” label on function key f5 if not f5
  • lab_f6 (lf6 / l6) โ€” label on function key f6 if not f6
  • lab_f7 (lf7 / l7) โ€” label on function key f7 if not f7
  • lab_f8 (lf8 / l8) โ€” label on function key f8 if not f8
  • lab_f9 (lf9 / l9) โ€” label on function key f9 if not f9
  • meta_off (rmm / mo) โ€” turn off meta mode
  • meta_on (smm / mm) โ€” turn on meta mode (8th-bit on)
  • newline (nel / nw) โ€” newline (behave like cr followed by lf)
  • pad_char (pad / pc) โ€” padding char (instead of null)
  • parm_dch (dch / DC) โ€” delete #1 characters (P*)
  • parm_delete_line (dl / DL) โ€” delete #1 lines (P*)
  • parm_down_cursor (cud / DO) โ€” down #1 lines (P*)
  • parm_ich (ich / IC) โ€” insert #1 characters (P*)
  • parm_index (indn / SF) โ€” scroll forward #1 lines (P)
  • parm_insert_line (il / AL) โ€” insert #1 lines (P*)
  • parm_left_cursor (cub / LE) โ€” move #1 characters to the left (P)
  • parm_right_cursor (cuf / RI) โ€” move #1 characters to the right (P*)
  • parm_rindex (rin / SR) โ€” scroll back #1 lines (P)
  • parm_up_cursor (cuu / UP) โ€” up #1 lines (P*)
  • pkey_key (pfkey / pk) โ€” program function key #1 to type string #2
  • pkey_local (pfloc / pl) โ€” program function key #1 to execute string #2
  • pkey_xmit (pfx / px) โ€” program function key #1 to transmit string #2
  • print_screen (mc0 / ps) โ€” print contents of screen
  • prtr_off (mc4 / pf) โ€” turn off printer
  • prtr_on (mc5 / po) โ€” turn on printer
  • repeat_char (rep / rp) โ€” repeat char #1 #2 times (P*)
  • reset_1string (rs1 / r1) โ€” reset string
  • reset_2string (rs2 / r2) โ€” reset string
  • reset_3string (rs3 / r3) โ€” reset string
  • reset_file (rf / rf) โ€” name of reset file
  • restore_cursor (rc / rc) โ€” restore cursor to position of last save_cursor
  • row_address (vpa / cv) โ€” vertical position #1 absolute (P)
  • save_cursor (sc / sc) โ€” save current cursor position (P)
  • scroll_forward (ind / sf) โ€” scroll text up (P)
  • scroll_reverse (ri / sr) โ€” scroll text down (P)
  • set_attributes (sgr / sa) โ€” define video attributes #1-#9 (PG9)
  • set_tab (hts / st) โ€” set a tab in every row, current

okay so we're still deep in the capability table and honestly? this is the part where the manpage just starts flexing ๐Ÿ’… stay with me bestie, we're going through every single one, no skipping, no cap.

  • set_window (wind, wi) โ€” current window is lines #1-#2, cols #3-#4
  • tab (ht, ta) โ€” tab to next 8-space hardware tab stop
  • to_status_line (tsl, ts) โ€” move to status line, column #1
  • underline_char (uc, uc) โ€” underline char and move past it
  • up_half_line (hu, hu) โ€” half a line up
  • init_prog (iprog, iP) โ€” path name of program for initialization

  • key_a1 (ka1, K1) โ€” upper left of keypad
  • key_a3 (ka3, K3) โ€” upper right of keypad
  • key_b2 (kb2, K2) โ€” center of keypad
  • key_c1 (kc1, K4) โ€” lower left of keypad
  • key_c3 (kc3, K5) โ€” lower right of keypad

โœจ keypad corner keys really said "we are the main characters of the numeric keypad" and honestly they ate.

  • prtr_non (mc5p, pO) โ€” turn on printer for #1 bytes
  • char_padding (rmp, rP) โ€” like ip but when in insert mode
  • acs_chars (acsc, ac) โ€” graphics charset pairs, based on vt100
  • plab_norm (pln, pn) โ€” program label #1 to show string #2
  • key_btab (kcbt, kB) โ€” back-tab key
  • enter_xon_mode (smxon, SX) โ€” turn on xon/xoff handshaking
  • exit_xon_mode (rmxon, RX) โ€” turn off xon/xoff handshaking
  • enter_am_mode (smam, SA) โ€” turn on automatic margins
  • exit_am_mode (rmam, RA) โ€” turn off automatic margins
  • xon_character (xonc, XN) โ€” XON character
  • xoff_character (xoffc, XF) โ€” XOFF character
  • ena_acs (enacs, eA) โ€” enable alternate char set
  • label_on (smln, LO) โ€” turn on soft labels
  • label_off (rmln, LF) โ€” turn off soft labels

okay brace yourself, this next chunk is the key-name section and it's long long ๐Ÿซถ but every single one matters so here we go:

  • key_beg (kbeg, @1) โ€” begin key
  • key_cancel (kcan, @2) โ€” cancel key
  • key_close (kclo, @3) โ€” close key
  • key_command (kcmd, @4) โ€” command key
  • key_copy (kcpy, @5) โ€” copy key
  • key_create (kcrt, @6) โ€” create key
  • key_end (kend, @7) โ€” end key
  • key_enter (kent, @8) โ€” enter/send key
  • key_exit (kext, @9) โ€” exit key
  • key_find (kfnd, @0) โ€” find key
  • key_help (khlp, %1) โ€” help key
  • key_mark (kmrk, %2) โ€” mark key
  • key_message (kmsg, %3) โ€” message key
  • key_move (kmov, %4) โ€” move key
  • key_next (knxt, %5) โ€” next key
  • key_open (kopn, %6) โ€” open key
  • key_options (kopt, %7) โ€” options key
  • key_previous (kprv, %8) โ€” previous key
  • key_print (kprt, %9) โ€” print key
  • key_redo (krdo, %0) โ€” redo key
  • key_reference (kref, &1) โ€” reference key
  • key_refresh (krfr, &2) โ€” refresh key
  • key_replace (krpl, &3) โ€” replace key
  • key_restart (krst, &4) โ€” restart key
  • key_resume (kres, &5) โ€” resume key
  • key_save (ksav, &6) โ€” save key
  • key_suspend (kspd, &7) โ€” suspend key
  • key_undo (kund, &8) โ€” undo key

and now the shifted versions, because these keys have a whole second personality ๐Ÿ‘‘:

  • key_sbeg (kBEG, &9) โ€” shifted begin key
  • key_scancel (kCAN, &0) โ€” shifted cancel key
  • key_scommand (kCMD, *1) โ€” shifted command key
  • key_scopy (kCPY, *2) โ€” shifted copy key
  • key_screate (kCRT, *3) โ€” shifted create key
  • key_sdc (kDC, *4) โ€” shifted delete-character key
  • key_sdl (kDL, *5) โ€” shifted delete-line key
  • key_select (kslt, *6) โ€” select key
  • key_send (kEND, *7) โ€” shifted end key
  • key_seol (kEOL, *8) โ€” shifted clear-to-end-of-line key
  • key_sexit (kEXT, *9) โ€” shifted exit key
  • key_sfind (kFND, *0) โ€” shifted find key
  • key_shelp (kHLP, #1) โ€” shifted help key
  • key_shome (kHOM, #2) โ€” shifted home key
  • key_sic (kIC, #3) โ€” shifted insert-character key
  • key_sleft (kLFT, #4) โ€” shifted left-arrow key
  • key_smessage (kMSG, %a) โ€” shifted message key
  • key_smove (kMOV, %b) โ€” shifted move key
  • key_snext (kNXT, %c) โ€” shifted next key
  • key_soptions (kOPT, %d) โ€” shifted options key
  • key_sprevious (kPRV, %e) โ€” shifted previous key
  • key_sprint (kPRT, %f) โ€” shifted print key
  • key_sredo (kRDO, %g) โ€” shifted redo key
  • key_sreplace (kRPL, %h) โ€” shifted replace key
  • key_sright (kRIT, %i) โ€” shifted right-arrow key
  • key_srsume (kRES, %j) โ€” shifted resume key
  • key_ssave (kSAV, !1) โ€” shifted save key
  • key_ssuspend (kSPD, !2) โ€” shifted suspend key
  • key_sundo (kUND, !3) โ€” shifted undo key
๐Ÿฉท yes, key_srsume is spelled like that in the list โ€” I'm not touching it, I don't make the rules, I just report them faithfully.
  • req_for_input (rfi, RF) โ€” send next input char (for ptys)

okay and now, the function key marathon ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ literally fifty-three of them, all iconic, all here:

  • key_f11 (kf11, F1) โ€” F11 function key
  • key_f12 (kf12, F2) โ€” F12 function key
  • key_f13 (kf13, F3) โ€” F13 function key
  • key_f14 (kf14, F4) โ€” F14 function key
  • key_f15 (kf15, F5) โ€” F15 function key
  • key_f16 (kf16, F6) โ€” F16 function key
  • key_f17 (kf17, F7) โ€” F17 function key
  • key_f18 (kf18, F8) โ€” F18 function key
  • key_f19 (kf19, F9) โ€” F19 function key
  • key_f20 (kf20, FA) โ€” F20 function key
  • key_f21 (kf21, FB) โ€” F21 function key
  • key_f22 (kf22, FC) โ€” F22 function key
  • key_f23 (kf23, FD) โ€” F23 function key
  • key_f24 (kf24, FE) โ€” F24 function key
  • key_f25 (kf25, FF) โ€” F25 function key
  • key_f26 (kf26, FG) โ€” F26 function key
  • key_f27 (kf27, FH) โ€” F27 function key
  • key_f28 (kf28, FI) โ€” F28 function key
  • key_f29 (kf29, FJ) โ€” F29 function key
  • key_f30 (kf30, FK) โ€” F30 function key
  • key_f31 (kf31, FL) โ€” F31 function key
  • key_f32 (kf32, FM) โ€” F32 function key
  • key_f33 (kf33, FN) โ€” F33 function key
  • key_f34 (kf34, FO) โ€” F34 function key
  • key_f35 (kf35, FP) โ€” F35 function key
  • key_f36 (kf36, FQ) โ€” F36 function key
  • key_f37 (kf37, FR) โ€” F37 function key
  • key_f38 (kf38, FS) โ€” F38 function key
  • key_f39 (kf39, FT) โ€” F39 function key
  • key_f40 (kf40, FU) โ€” F40 function key
  • key_f41 (kf41, FV) โ€” F41 function key
  • key_f42 (kf42, FW) โ€” F42 function key
  • key_f43 (kf43, FX) โ€” F43 function key
  • key_f44 (kf44, FY) โ€” F44 function key
  • key_f45 (kf45, FZ) โ€” F45 function key
  • key_f46 (kf46, Fa) โ€” F46 function key
  • key_f47 (kf47, Fb) โ€” F47 function key
  • key_f48 (kf48, Fc) โ€” F48 function key
  • key_f49 (kf49, Fd) โ€” F49 function key
  • key_f50 (kf50, Fe) โ€” F50 function key
  • key_f51 (kf51, Ff) โ€” F51 function key
  • key_f52 (kf52, Fg) โ€” F52 function key
  • key_f53 (kf53, Fh) โ€” F53 function key
  • key_f54 (kf54, Fi) โ€” F54 function key
  • key_f55 (kf55, Fj) โ€” F55 function key
  • key_f56 (kf56, Fk) โ€” F56 function key
  • key_f57 (kf57, Fl) โ€” F57 function key
  • key_f58 (kf58, Fm) โ€” F58 function key
  • key_f59 (kf59, Fn) โ€” F59 function key
  • key_f60 (kf60, Fo) โ€” F60 function key
  • key_f61 (kf61, Fp) โ€” F61 function key
  • key_f62 (kf62, Fq) โ€” F62 function key
  • key_f63 (kf63, Fr) โ€” F63 function key

๐Ÿ’€ and yes, the termcap codes go F1โ€ฆFZ then lowercase Faโ€ฆFr โ€” that's not me being chaotic, that's literally what's written, and we respect it.


  • clr_bol (el1, cb) โ€” Clear to beginning of line
  • clear_margins (mgc, MC) โ€” clear right and left soft margins
  • set_left_margin (smgl, ML) โ€” set left soft margin at current column (not in BSD termcap)
  • set_right_margin (smgr, MR) โ€” set right soft margin at current column
  • label_format (fln, Lf) โ€” label format
  • set_clock (sclk, SC) โ€” set clock, #1 hrs #2 mins #3 secs
  • display_clock (dclk, DK) โ€” display clock
  • remove_clock (rmclk, RC) โ€” remove clock

๐Ÿฆ‹ and then it just goes fully sci-fi with windows and telephones, like okay multitasking queen:

  • create_window (cwin, CW) โ€” define a window #1 from #2,#3 to #4,#5
  • goto_window (wingo, WG) โ€” go to window #1
  • hangup (hup, HU) โ€” hang-up phone
  • dial_phone (dial, DI) โ€” dial number #1
  • quick_dial (qdial, QD) โ€” dial number #1 without checking
  • tone (tone, TO) โ€” select touch tone dialing
  • pulse (pulse, PU) โ€” select pulse dialing
  • flash_hook (hook, fh) โ€” flash switch hook
  • fixed_pause (pause, PA) โ€” pause for 2-3 seconds
  • wait_tone (wait, WA) โ€” wait for dial-tone

like bestie this is a terminal definition, why does it know how to dial a phone ๐Ÿ˜ญ iconic honestly.


  • user0 (u0, u0) โ€” User string #0
  • user1 (u1, u1) โ€” User string #1
  • user2 (u2, u2) โ€” User string #2
  • user3 (u3, u3) โ€” User string #3
  • user4 (u4, u4) โ€” User string #4
  • user5 (u5, u5) โ€” User string #5
  • user6 (u6, u6) โ€” User string #6
  • user7 (u7, u7) โ€” User string #7
  • user8 (u8, u8) โ€” User string #8
  • user9 (u9, u9) โ€” User string #9

and finally the colour corner, which is where it starts getting pretty ๐ŸŒˆ:

  • orig_pair (op, op) โ€” Set default pair to its original value
  • orig_colors (oc, oc) โ€” Set all color pairs to the original ones
  • initialize_color (initc, Ic) โ€” initialize color #1 to (#2,#3,#4)
  • initialize_pair (initp, Ip) โ€” Initialize color pair #1 to

โ€ฆand we're literally mid-sentence, bestie ๐Ÿ‘€ not me leaving you hanging, the table just keeps going โ€”

The wrapped tail of that last description is literally fg=(#2,#3,#4), bg=(#5,#6,#7) โ€” keep it exactly like that, bestie. ๐Ÿ’…

For each row below: capability name, TI code, TC code, and the description. No skipping, no summarizing, weโ€™re doing the whole list. ๐Ÿซถ

  • set_color_pair โ€” TI scp, TC sp โ€” set the current color pair to #1.
  • set_foreground โ€” TI setf, TC Sf โ€” set the foreground color to #1.
  • set_background โ€” TI setb, TC Sb โ€” set the background color to #1.
  • change_char_pitch โ€” TI cpi, TC ZA โ€” change the number of characters per inch to #1.
  • change_line_pitch โ€” TI lpi, TC ZB โ€” change the number of lines per inch to #1.
  • change_res_horz โ€” TI chr, TC ZC โ€” change the horizontal resolution to #1.
  • change_res_vert โ€” TI cvr, TC ZD โ€” change the vertical resolution to #1.
  • define_char โ€” TI defc, TC ZE โ€” define a character #1, #2 dots wide, descender #3.
  • enter_doublewide_mode โ€” TI swidm, TC ZF โ€” enter double-wide mode.
  • enter_draft_quality โ€” TI sdrfq, TC ZG โ€” enter draft-quality mode.
  • enter_italics_mode โ€” TI sitm, TC ZH โ€” enter italic mode.
  • enter_leftward_mode โ€” TI slm, TC ZI โ€” start leftward carriage motion.
  • enter_micro_mode โ€” TI smicm, TC ZJ โ€” start micro-motion mode.
  • enter_near_letter_quality โ€” TI snlq, TC ZK โ€” enter NLQ mode.
  • enter_normal_quality โ€” TI snrmq, TC ZL โ€” enter normal-quality mode.
  • enter_shadow_mode โ€” TI sshm, TC ZM โ€” enter shadow-print mode.
  • enter_subscript_mode โ€” TI ssubm, TC ZN โ€” enter subscript mode.
  • enter_superscript_mode โ€” TI ssupm, TC ZO โ€” enter superscript mode.
  • enter_upward_mode โ€” TI sum, TC ZP โ€” start upward carriage motion.
  • exit_doublewide_mode โ€” TI rwidm, TC ZQ โ€” end double-wide mode.
  • exit_italics_mode โ€” TI ritm, TC ZR โ€” end italic mode.
  • exit_leftward_mode โ€” TI rlm, TC ZS โ€” end left-motion mode.
  • exit_micro_mode โ€” TI rmicm, TC ZT โ€” end micro-motion mode.
  • exit_shadow_mode โ€” TI rshm, TC ZU โ€” end shadow-print mode.
  • exit_subscript_mode โ€” TI rsubm, TC ZV โ€” end subscript mode.
  • exit_superscript_mode โ€” TI rsupm, TC ZW โ€” end superscript mode.
  • exit_upward_mode โ€” TI rum, TC ZX โ€” end reverse character motion.
  • micro_column_address โ€” TI mhpa, TC ZY โ€” like column_address in micro mode.
  • micro_down โ€” TI mcud1, TC ZZ โ€” like cursor_down in micro mode.
  • micro_left โ€” TI mcub1, TC Za โ€” like cursor_left in micro mode.
  • micro_right โ€” TI mcuf1, TC Zb โ€” like cursor_right in micro mode.
  • micro_row_address โ€” TI mvpa, TC Zc โ€” like row_address #1 in micro mode.
  • micro_up โ€” TI mcuu1, TC Zd โ€” like cursor_up in micro mode.
  • order_of_pins โ€” TI porder, TC Ze โ€” match software bits to print-head pins.
  • parm_down_micro โ€” TI mcud, TC Zf โ€” like parm_down_cursor in micro mode.
  • parm_left_micro โ€” TI mcub, TC Zg โ€” like parm_left_cursor in micro mode.
  • parm_right_micro โ€” TI mcuf, TC Zh โ€” like parm_right_cursor in micro mode.
  • parm_up_micro โ€” TI mcuu, TC Zi โ€” like parm_up_cursor in micro mode.
  • select_char_set โ€” TI scs, TC Zj โ€” select character set, #1.
  • set_bottom_margin โ€” TI smgb, TC Zk โ€” set the bottom margin at the current line.
  • set_bottom_margin_parm โ€” TI smgbp, TC Zl โ€” set the bottom margin at line #1 or (if smgtp is not given) #2 lines from bottom.
  • set_left_margin_parm โ€” TI smglp, TC Zm โ€” set left (right) margin at column #1.
  • set_right_margin_parm โ€” TI smgrp, TC Zn โ€” set right margin at column #1.
  • set_top_margin โ€” TI smgt, TC Zo โ€” set the top margin at the current line.
  • set_top_margin_parm โ€” TI smgtp, TC Zp โ€” set top (bottom) margin at row #1.
  • start_bit_image โ€” TI sbim, TC Zq โ€” start printing bit image graphics.
  • start_char_set_def โ€” TI scsd, TC Zr โ€” start character set definition #1, with #2 characters in the set.
  • stop_bit_image โ€” TI rbim, TC Zs โ€” stop printing bit image graphics.
  • stop_char_set_def โ€” TI rcsd, TC Zt โ€” end definition of character set #1.
  • subscript_characters โ€” TI subcs, TC Zu โ€” list of subscriptable characters.
  • superscript_characters โ€” TI supcs, TC Zv โ€” list of superscriptable characters.
  • these_cause_cr โ€” TI docr, TC Zw โ€” printing any of these characters causes CR.
  • zero_motion โ€” TI zerom, TC Zx โ€” no motion for subsequent character.

Plot twist time ๐Ÿ‘€: the following string capabilities are present in the SVr4.0 term structure, but were originally not documented in the man page.

  • char_set_names โ€” TI csnm, TC Zy โ€” produce the #1'th item from the list of character set names.
  • key_mouse โ€” TI kmous, TC Km โ€” mouse event has occurred.
  • mouse_info โ€” TI minfo, TC Mi โ€” mouse status information.
  • req_mouse_pos โ€” TI reqmp, TC RQ โ€” request mouse position.
  • get_mouse โ€” TI getm, TC Gm โ€” curses should get button events; parameter #1 is not documented.
  • set_a_foreground โ€” TI setaf, TC AF โ€” set foreground color to #1, using ANSI escape.
  • set_a_background โ€” TI setab, TC AB โ€” set background color to #1, using ANSI escape.
  • pkey_plab โ€” TI pfxl, TC xl โ€” program function key #1 to type string #2 and show string #3.
  • device_type โ€” TI devt, TC dv โ€” indicate language, codeset support.
  • code_set_init โ€” TI csin, TC ci โ€” init sequence for multiple codesets.
  • set0_des_seq โ€” TI s0ds, TC s0 โ€” shift to codeset 0 (EUC set 0, ASCII).
  • set1_des_seq โ€” TI s1ds, TC s1 โ€” shift to codeset 1.
  • set2_des_seq โ€” TI s2ds, TC s2 โ€” shift to codeset 2.
  • set3_des_seq โ€” TI s3ds, TC s3 โ€” shift to codeset 3.
  • set_lr_margin โ€” TI smglr, TC ML โ€” set both left and right margins to #1, #2. (ML is not in BSD termcap).
  • set_tb_margin โ€” TI smgtb, TC MT โ€” sets both top and bottom margins to #1, #2.
  • bit_image_repeat โ€” TI birep, TC Xy โ€” repeat bit image cell #1 #2 times.
  • bit_image_newline โ€” TI binel, TC Zz โ€” move to the next row of the bit image.
  • bit_image_carriage_return โ€” TI bicr, TC Yv โ€” move to the beginning of the same row.
  • color_names โ€” TI colornm, TC Yw โ€” give name for color #1.
  • define_bit_image_region โ€” TI defbi, TC Yx โ€” define rectangular bit image region.
  • end_bit_image_region โ€” TI endbi, TC Yy โ€” end a bit-image region.
  • set_color_band โ€” TI setcolor, TC Yz โ€” change to ribbon color #1.
  • set_page_length โ€” TI slines, TC YZ โ€” set page length to #1 lines.
  • display_pc_char โ€” TI dispc, TC S1 โ€” display PC character #1.
  • enter_pc_charset_mode โ€” TI smpch, TC S2 โ€” enter PC character display mode.
  • exit_pc_charset_mode โ€” TI rmpch, TC S3 โ€” exit PC character display mode.
  • enter_scancode_mode โ€” TI smsc, TC S4 โ€” enter PC scancode mode.
  • exit_scancode_mode โ€” TI rmsc, TC S5 โ€” exit PC scancode mode.
  • pc_term_options โ€” TI pctrm, TC S6 โ€” PC terminal options.
  • scancode_escape โ€” TI scesc, TC S7 โ€” escape for scancode emulation.
  • alt_scancode_esc โ€” TI scesa, TC S8 โ€” alternate escape for scancode emulation.

The XSI Curses standard added these hardcopy capabilities. They were used in some post-4.1 versions of System V curses, e.g., Solaris 2.5 and IRIX 6.x. Except for YI, the ncurses termcap names for them are invented. According to the XSI Curses standard, they have no termcap names. If your compiled terminfo entries use these, they may not be binary-compatible with System V terminfo entries after SVr4.1; beware!

โš ๏ธ Beware! That compatibility note is not a vibe โ€” itโ€™s a real warning. Do not sleep on it. ๐Ÿ’€
  • enter_horizontal_hl_mode โ€” TI ehhlm, TC Xh โ€” enter horizontal highlight mode.
  • enter_left_hl_mode โ€” TI elhlm, TC Xl โ€” enter left highlight mode.
  • enter_low_hl_mode โ€” TI elohlm, TC Xo โ€” enter low highlight mode.
  • enter_right_hl_mode โ€” TI erhlm, TC Xr โ€” enter right highlight mode.
  • enter_top_hl_mode โ€” TI ethlm, TC Xt โ€” enter top highlight mode.
  • enter_vertical_hl_mode โ€” TI evhlm, TC Xv โ€” enter vertical highlight mode.
  • set_a_attributes โ€” TI sgr1, TC sA โ€” define the second set of video attributes #1-#6.
  • set_pglen_inch โ€” TI slength, TC YI โ€” set page length to #1 hundredth of an inch (some implementations use sL for termcap).

๐Ÿงš User-Defined Capabilities ๐Ÿงš

The preceding section listed the standard capabilities. Some are esoteric โ€” they support functionality that terminal emulators do not implement, or may never have been realized in manufactured hardware. And occasionally, emulators have special features that are awkward or impossible to represent via standard capabilities. Thatโ€™s the whole reason user-defined capabilities exist, bestie. ๐Ÿซถ

Okay so ncurses fixes this whole limitation sitch by letting you do user-defined capabilities. ๐Ÿ’… The tic and infocmp programs both give you an -x option for exactly this. When -x is used, tic treats unknown capabilities as user-defined. Like, if tic bumps into a capability name it doesnโ€™t recognize, it infers the capabilityโ€™s type โ€” Boolean, numeric, or string โ€” from the syntax of the capability value, and makes an extended table entry for that capability. use_extended_names(3X) makes this info conditionally available to applications. And ncurses library functions supply callers with capability data, and the interpretation of that data is mostly up to the application. ๐Ÿซถ

  • ncurses treats user-defined string capabilities whose names begin with k as function keys.
  • Capability types (Boolean, numeric, or string) determined by tic can be inferred by successful tigetflag(3X), tigetnum(3X), and tigetstr(3X) calls.
  • If the capability name happens to be two characters, the capability is also available through the termcap interface.

Now, termcap is said to be extensible because it mandates no capabilities, but in practice it has been limited to those defined by terminfo implementations. As a rule, employ only user-defined capabilities of Boolean and numeric type with termcap applications to avoid overrunning the 1023 byte limit assumed by termcap implementations and their applications. ๐Ÿ’€ Specifically, support for extended sets of function keys (past the 60 numbered keys and the handful of special named keys) is better achieved with longer names available via terminfo.

The ncurses library uses a few of these user-defined capabilities, as described in user_caps(5). For other user-defined capabilities, including function keys, consult the source form of the terminal database, terminfo.src, under the heading โ€œNCURSES USER-DEFINABLE CAPABILITIESโ€.

๐ŸŽ€ A Sample Entry ๐ŸŽ€

The following entry, describing an ANSI X3.64- (or ECMA-48-) -standard terminal (henceforth โ€œANSI-standardโ€ for brevity), is representative of what a terminfo entry for a modern terminal typically looks like.

       ansi|ansi/pc-term compatible with color,
               am, mc5i, mir, msgr,
               colors#8, cols#80, it#8, lines#24, ncv#3, pairs#64,
               acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260
                    j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303
                    u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376,
               bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J,
               cr=^M, cub=\E[%p1%dD, cub1=\E[D, cud=\E[%p1%dB, cud1=\E[B,
               cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH,
               cuu=\E[%p1%dA, cuu1=\E[A, dch=\E[%p1%dP, dch1=\E[P,
               dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
               el1=\E[1K, home=\E[H, hpa=\E[%i%p1%dG, ht=\E[I, hts=\EH,
               ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J,
               indn=\E[%p1%dS, invis=\E[8m, kbs=^H, kcbt=\E[Z, kcub1=\E[D,
               kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L,
               mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, op=\E[39;49m,
               rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, rin=\E[%p1%dT,
               rmacs=\E[10m, rmpch=\E[10m, rmso=\E[m, rmul=\E[m,
               s0ds=\E(B, s1ds=\E)B, s2ds=\E*B, s3ds=\E+B,
               setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
               sgr=\E[0;10%?%p1%t;7%;
                          %?%p2%t;4%;
                          %?%p3%t;7%;
                          %?%p4%t;5%;
                          %?%p6%t;1%;
                          %?%p7%t;8%;
                          %?%p9%t;11%;m,
               sgr0=\E[0;10m, smacs=\E[11m, smpch=\E[11m, smso=\E[7m,
               smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
               u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,

Entries may continue onto multiple lines by placing white space at the beginning of each line except the first. Comments may be included on lines beginning with #. Capabilities in terminfo are of three types:

  • Boolean capabilities which indicate that the terminal has some particular feature,
  • numeric capabilities giving the size of the terminal or the size of particular delays, and
  • string capabilities, which give a sequence which can be used to perform particular terminal operations.

๐ŸŒธ Types of Capabilities ๐ŸŒธ

All capabilities have names. For instance, the fact that ANSI-standard terminals have automatic margins (i.e., an automatic return and line-feed when the end of a line is reached) is indicated by the capability am. Hence the description of ansi includes am. Numeric capabilities are followed by the character # and then a positive value. Thus cols, which indicates the number of columns the terminal has, gives the value 80 for ansi. Values for numeric capabilities may be specified in decimal, octal, or hexadecimal, using the C programming language conventions (e.g., 255, 0377 and 0xff or 0xFF).

Finally, string valued capabilities, such as el (clear to end of line sequence) are given by the two-character code, an =, and then a string ending at the next following ,.

A number of escape sequences are provided in the string valued capabilities for easy encoding of characters there:

  • Both \E and \e map to an ESCAPE character,
  • ^x maps to a control-x for any appropriate x, and
  • the sequences \n, \l, \r, \t, \b, \f, and \s produce newline, line-feed, return, tab, backspace, form-feed, and space, respectively.

X/Open Curses does not say what โ€œappropriate xโ€ might be. In practice, that is a printable ASCII graphic character. The special case ^? is interpreted as DEL (127). In all other cases, the character value is logically โ€œandโ€-ed with 0x1f, mapping to ASCII control codes in the range 0 through 31.

Other escapes include

  • \^ for ^,
  • \\ for \,
  • \, for comma,
  • \: for :,
  • and \0 for null.
\0 will produce \200, which does not terminate a string but behaves as a null character on most terminals, providing CS7 is specified. See stty(1).

The reason for this quirk is to maintain binary compatibility of the compiled terminfo files with other implementations, e.g., the SVr4 systems, which document this. Compiled terminfo files use null-terminated strings, with no lengths. Modifying this would require a new binary format, which would not work with other implementations.

Finally, characters may be given as three octal digits after a \.

A delay in milliseconds may appear anywhere in a string capability, enclosed in $<..> brackets, as in el=\EK$<5>, and padding characters are supplied by tputs(3X) to provide this delay.

  • The delay must be a number with at most one decimal place of precision; it may be followed by suffixes * or / or both.
  • A * indicates that the padding required is proportional to the number of lines affected by the operation, and the amount given is the per-affected-unit padding required. (In the case of insert character, the factor is still the number of lines affected.)

Normally, padding is advisory if the device has the xon capability; it is used for cost computation but does not trigger delays.

  • A / suffix indicates that the padding is mandatory and forces a delay of the given number of milliseconds even on devices for which xon is present to indicate flow control.

Sometimes individual capabilities must be commented out. To do this, put a period before the capability name. For example, see the second ind in the example above.

๐Ÿฆ‹ Fetching Compiled Descriptions ๐Ÿฆ‹

Terminal descriptions in ncurses are stored in terminal databases. These databases, which are found by their pathname, may be configured either as directory trees or hashed databases (see term(5)),

The library uses a compiled-in list of pathnames, which can be overridden by environment variables. Before starting to search, ncurses checks the search list, eliminating duplicates and pathnames where no terminal database is found. The ncurses library reads the first description which passes its consistency checks.

  • The environment variable TERMINFO is checked first, for a terminal database containing the terminal description.
  • Next, ncurses looks in $HOME/.terminfo for a compiled description.

This is an optional feature which may be omitted entirely from the library, or limited to prevent accidental use by privileged applications.

  • Next, if the environment variable TERMINFO_DIRS is set, ncurses interprets the contents of that variable as a list of colon-separated pathnames of terminal databases to be searched.

An empty pathname (i.e., if the variable begins or ends with a colon, or contains adjacent colons) is interpreted as the system location /usr/share/terminfo.

  • Finally, ncurses searches these compiled-in locations:
    • a list of directories (/etc/terminfo:/usr/share/terminfo:/lib/terminfo:/usr/lib/terminfo), and
    • the system terminfo directory, /usr/share/terminfo

The TERMINFO variable can contain a terminal description instead of the pathname of a terminal database. If this variable begins with hex: or b64: then ncurses reads a terminal description from hexadecimal- or base64-encoded data, and if that description matches the name sought, will use that. This encoded data can be set using the -Q option of tic or infocmp.

The preceding addresses the usual configuration of ncurses, which uses terminal descriptions prepared in terminfo format. While termcap is less expressive, ncurses can also be configured to read termcap descriptions. In that configuration, it checks the TERMCAP and TERMPATH variables (for content and search path, respectively) after the system terminal database.

โœจ Preparing Descriptions โœจ

We now outline how to prepare descriptions of terminals. The most effective way to prepare a terminal description is by imitating the description of a similar terminal in terminfo and to build up a description gradually, using partial descriptions with vi or some other screen-oriented program to check that they are correct. Be aware that a very unusual terminal may expose deficiencies in the ability of the terminfo file to describe it or bugs in the screen-handling code of the test program.

To get the padding for insert line right (if the terminal manufacturer did not document it) a severe test is to edit a large file at 9600 baud, delete 16 or so lines from the middle of the screen, then hit the u key several times quickly. If the terminal messes up, more padding is usually needed. A similar test can be used for insert character.

โœจ Basic Capabilities โœจ

Okay so like, the absolute basics first, bestie. ๐Ÿ’…

The number of columns on each line is the cols numeric capability. If the terminal is a CRT, the number of lines on the screen is lines. If the terminal wraps around to the beginning of the next line when it hits the right margin, it gets the am capability. If it can clear its screen and leave the cursor in the home position, that's the clear string capability. If the terminal overstrikes โ€” like, it doesn't clear a position when a character is struck over it โ€” then it has os. If it's a printing terminal with no soft copy unit, give it both hc and os. (os applies to storage scope terminals, such as the TEKTRONIX 4010 series, as well as hard copy and APL terminals โ€” so like, all of those, yeah.)

If there's a code to move the cursor to the left edge of the current line, that's cr (normally carriage return, control/M). If there's a code for an audible signal โ€” bell, beep, whatever โ€” that's bel. ๐Ÿ””

If there's a code to move the cursor one position to the left (backspace, for example), that capability is cub1. Same vibe for right, up, and down: cuf1, cuu1, and cud1. These local cursor motions should not alter the text they pass over โ€” like, you would not normally use cuf1= because the space would erase the character it moved over. ๐Ÿ™ˆ

โš ๏ธ A very important point here: the local cursor motions encoded in terminfo are undefined at the left and top edges of a CRT terminal. Programs should never attempt to backspace around the left edge, unless bw is given, and never attempt to go up locally off the top. Fr fr, don't do it.

To scroll text up, a program goes to the bottom left corner of the screen and sends the ind (index) string.

To scroll text down, a program goes to the top left corner of the screen and sends the ri (reverse index) string. The strings ind and ri are undefined when they're not on their respective corners of the screen.

Parameterized versions of the scrolling sequences are indn and rin โ€” same semantics as ind and ri, except they take one parameter and scroll that many lines. They're also undefined except at the appropriate edge of the screen. โœจ

The am capability tells you whether the cursor sticks at the right edge of the screen when text is output, but that doesn't necessarily apply to a cuf1 from the last column. The only local motion that's defined from the left edge is: if bw is given, then a cub1 from the left edge will move to the right edge of the previous line. If bw is not given, the effect is undefined. This is useful for drawing a box around the edge of the screen, for example. ๐ŸŽ€

If the terminal has switch selectable automatic margins, the terminfo file usually assumes this is on โ€” i.e., am. If the terminal has a command that moves to the first column of the next line, that command can be given as nel (newline). It doesn't matter if the command clears the remainder of the current line, so if the terminal has no cr and lf, it may still be possible to craft a working nel out of one or both of them. Iconic problem-solving energy, honestly.

These capabilities suffice to describe hard-copy and "glass-tty" terminals. So the model 33 teletype is described as:

33|tty33|tty|model 33 teletype,
        bel=^G, cols#72, cr=^M, cud1=^J, hc, ind=^J, os,

while the Lear Siegler ADM-3 is described as:

adm3|3|lsi adm3,
        am, bel=^G, clear=^Z, cols#80, cr=^M, cub1=^H, cud1=^J,
        ind=^J, lines#24,

๐ŸŒธ Parameterized Strings ๐ŸŒธ

Cursor addressing and other strings that need parameters in the terminal are described by a parameterized string capability, with printf-like escapes such as %x in it. So for cursor addressing, you give the cup capability using two parameters: the line and the column to address to. (Lines and columns are numbered from zero and refer to the physical screen visible to the user โ€” not to any unseen memory.) If the terminal has memory-relative cursor addressing, that can be indicated by mrcup.

The parameter mechanism uses a stack and special % codes to manipulate it. Typically a sequence pushes one of the parameters onto the stack and then prints it in some format. Print (e.g. %d) is a special case. Other operations, including %t, pop their operand from the stack. And yeah, more complex operations are often necessary โ€” for example in the sgr string. ๐Ÿ˜ญ

The % encodings have the following meanings:

  • %% โ€” outputs %
  • %[[:]flags][width[.precision]][doxXs] โ€” as in printf(3), flags are [-+#] and space. Use a : to let the next character be a - flag, avoiding interpreting %- as an operator.
  • %c โ€” print pop() like %c in printf
  • %s โ€” print pop() like %s in printf
  • %p[1-9] โ€” push i'th parameter
  • %P[a-z] โ€” set dynamic variable [a-z] to pop()
  • %g[a-z] โ€” get dynamic variable [a-z] and push it
  • %P[A-Z] โ€” set static variable [a-z] to pop()
  • %g[A-Z] โ€” get static variable [a-z] and push it

The terms "static" and "dynamic" are lowkey misleading. Historically, these are simply two different sets of variables, whose values are not reset between calls to tparm(3X). However, that fact isn't documented in other implementations, and relying on it will adversely impact portability to other implementations:

  • SVr2 curses supported dynamic variables. Those are set only by a %P operator. A %g for a given variable without first setting it with %P will give unpredictable results, because dynamic variables are an uninitialized local array on the stack in the tparm function.
  • SVr3.2 curses supported static variables. Those are an array in the TERMINAL structure (declared in term.h), and are zeroed automatically when the setupterm function allocates the data.
  • SVr4 curses made no further improvements to the dynamic/static variable feature.
  • Solaris XPG4 curses does not distinguish between dynamic and static variables. They are the same. Like SVr4 curses, XPG4 curses does not initialize these explicitly.
  • Before version 6.3, ncurses stores both dynamic and static variables in persistent storage, initialized to zeros.
  • Beginning with version 6.3, ncurses stores static and dynamic variables in the same manner as SVr4.
    • Unlike other implementations, ncurses zeros dynamic variables before the first %g or %P operator.
    • Like SVr2, the scope of dynamic variables in ncurses is within the current call to tparm. Use static variables if persistent storage is needed.
  • %'c' โ€” char constant c
  • %{nn} โ€” integer constant nn
  • %l โ€” push strlen(pop)
  • %+, %-, %*, %/, %m โ€” arithmetic (%m is mod): push(pop() op pop())
  • %&, %|, %^ โ€” bit operations ("and", "or" and exclusive "or"): push(pop() op pop())
  • %=, %>, %< โ€” logical operations: push(pop() op pop())
  • %A, %O โ€” logical "and" and "or" operations (for conditionals)
  • %!, %~ โ€” unary operations (logical and bit complement): push(op pop())
  • %i โ€” add 1 to first two parameters (for ANSI terminals)
  • %? expr %t thenpart %e elsepart %; โ€” this forms an if-then-else. The %e elsepart is optional. Usually the %? expr part pushes a value onto the stack, and %t pops it from the stack, testing if it's nonzero (true). If it's zero (false), control passes to the %e (else) part.

It's possible to form else-ifs ร  la Algol 68:

%? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %;

where ci are conditions and bi are bodies.

Use the -f option of tic or infocmp to see the structure of if-then-else's. Some strings โ€” sgr, for example โ€” can be very complicated when written on one line. The -f option splits the string into lines with the parts indented. ๐Ÿซถ

Binary operations are in postfix form with the operands in the usual order. That is, to get x-5 you'd use %gx%{5}%-. %P and %g variables are persistent across escape-string evaluations.

Consider the HP2645, which, to get to line 3 and column 12, needs to be sent \E&a12c03Y padded for 6 milliseconds. The order of the lines and columns is inverted here, and the lines and column are printed as two digits. The corresponding terminal description is expressed thus:

cup=\E&a%p2%dc%p1%dY$<6>,

The Microterm ACT-IV needs the current line and column sent preceded by a ^T, with the line and column simply encoded in binary:

cup=^T%p1%c%p2%c

Terminals which use %c need to be able to backspace the cursor (cub1) and to move the cursor up one line on the screen (cuu1). This is necessary because it's not always safe to transmit \n, ^D and \r โ€” the system may change or discard them. (The library routines dealing with terminfo set tty modes so that tabs are never expanded, so \t is safe to send. This turns out to be essential for the Ann Arbor 4080.) ๐Ÿ‘‘

A final example is the LSI ADM-3A, which uses line and column offset by a space, thus:

cup=\E=%p1%' '%+%c%p2%' '%+%c

After sending \E=, this pushes the first parameter, pushes the ASCII value for a space (32), adds them (pushing the sum on the stack in place of the two previous values), and outputs that value as a character. Then the same is done for the second parameter. More complex arithmetic is possible using the stack. Literally so much range. ๐ŸŒˆ


๐Ÿฆ‹ Cursor Motions ๐Ÿฆ‹

If the terminal has a fast way to home the cursor (to the very upper left corner of the screen), that can be given as home. Similarly, a fast way of getting to the lower left-hand corner can be given as ll โ€” this may involve going up with cuu1 from the home position, but a program should never do this itself (unless ll does), because it can make no assumption about the effect of moving up from the home position. ๐Ÿšจ

Note that the home position is the same as addressing to (0,0): the top left corner of the screen, not of memory. (Thus, the \EH sequence on HP terminals cannot be used for home.)

okay so if the terminal has line or column absolute cursor addressing, you can hand those over as single-parameter capabilities: hpa (horizontal position absolute) and vpa (vertical position absolute). Sometimes these are shorter than the more general two-parameter sequence (as with the hp2645) and can be used in preference to cup. If there are parameterized local motions (e.g., move n spaces to the right), those can be given as cud, cub, cuf, and cuu with a single parameter indicating how many spaces to move. Theyโ€™re primarily useful if the terminal does not have cup, such as the TEKTRONIX 4025.

If the terminal needs to be in a special mode when running a program that uses these capabilities, the codes to enter and exit this mode can be given as smcup and rmcup. This arises, for example, from terminals like the Concept with more than one page of memory. If the terminal has only memory relative cursor addressing and not screen relative cursor addressing, a one screen-sized window must be fixed into the terminal for cursor addressing to work properly. This is also used for the TEKTRONIX 4025, where smcup sets the command character to be the one used by terminfo. If the smcup sequence will not restore the screen after an rmcup sequence is output (to the state prior to outputting rmcup), specify nrrmc.

๐Ÿ’… Margins ๐Ÿ’…

SVr4 (and X/Open Curses) list several string capabilities for setting margins. Two were intended for use with terminals, and another six were intended for use with printers.

  • The two terminal capabilities assume that the terminal may have the capability of setting the left and/or right margin at the current cursor column position.
  • The printer capabilities assume that the printer may have two types of capability:
    • the ability to set a top and/or bottom margin using the current line position, and
    • parameterized capabilities for setting the top, bottom, left, right margins given the number of lines or columns.

In practice, the categorization into โ€œterminalโ€ and โ€œprinterโ€ is not suitable:

  • The AT&T SVr4 terminal database uses smgl four times, for AT&T hardware. Three of the four are printers. They lack the ability to set left/right margins by specifying the column.
  • Other (non-AT&T) terminals may support margins but using different assumptions from AT&T. For instance, the DEC VT420 supports left/right margins, but only using a column parameter. As an added complication, the VT420 uses two settings to fully enable left/right margins (left/right margin mode, and origin mode). The former enables the margins, which causes printed text to wrap within margins, but the latter is needed to prevent cursor-addressing outside those margins. Both DEC VT420 left/right margins are set with a single control sequence. If either is omitted, the corresponding margin is set to the left or right edge of the display (rather than leaving the margin unmodified).

These are the margin-related capabilities:

  • smgl โ€” Set left margin at current column
  • smgr โ€” Set right margin at current column
  • smgb โ€” Set bottom margin at current line
  • smgt โ€” Set top margin at current line
  • smgbp โ€” Set bottom margin at line N
  • smglp โ€” Set left margin at column N
  • smgrp โ€” Set right margin at column N
  • smgtp โ€” Set top margin at line N
  • smglr โ€” Set both left and right margins to L and R
  • smgtb โ€” Set both top and bottom margins to T and B

When writing an application that uses these string capabilities, the pairs should be first checked to see if each capability in the pair is set or only one is set:

  • If both smglp and smgrp are set, each is used with a single argument, N, that gives the column number of the left and right margin, respectively.
  • If both smgtp and smgbp are set, each is used to set the top and bottom margin, respectively:
    • smgtp is used with a single argument, N, the line number of the top margin.
    • smgbp is used with two arguments, N and M, that give the line number of the bottom margin, the first counting from the top of the page and the second counting from the bottom. This accommodates the two styles of specifying the bottom margin in different manufacturers' printers.

When designing a terminfo entry for a printer that has a settable bottom margin, only the first or second argument should be used, depending on the printer. When developing an application that uses smgbp to set the bottom margin, both arguments must be given.

Conversely, when only one capability in the pair is set:

  • If only one of smglp and smgrp is set, then it is used with two arguments, the column number of the left and right margins, in that order.
  • Likewise, if only one of smgtp and smgbp is set, then it is used with two arguments that give the top and bottom margins, in that order, counting from the top of the page.

When designing a terminfo entry for a printer that requires setting both left and right or top and bottom margins simultaneously, only one capability in the pairs smglp and smgrp or smgtp and smgbp should be defined, leaving the other unset.

bestie, except for very old terminal descriptions, e.g., those developed for SVr4, the scheme just described should be considered obsolete. An improved set of capabilities was added late in the SVr4 releases (smglr and smgtb), which explicitly use two parameters for setting the left/right or top/bottom margins.

When setting margins, the line- and column-values are zero-based.

The mgc string capability should be defined. Applications such as tabs(1) rely upon this to reset all margins.

๐Ÿงผ Area Clears ๐Ÿงผ

If the terminal can clear from the current position to the end of the line, leaving the cursor where it is, this should be given as el. If the terminal can clear from the beginning of the line to the current position inclusive, leaving the cursor where it is, this should be given as el1. If the terminal can clear from the current position to the end of the display, then this should be given as ed. ed is only defined from the first column of a line. (Thus, it can be simulated by a request to delete a large number of lines, if a true ed is not available.)

๐ŸŒ€ Insert/Delete Line and Vertical Motions ๐ŸŒ€

If the terminal can open a new blank line before the line where the cursor is, this should be given as il1; this is done only from the first position of a line. The cursor must then appear on the newly blank line. If the terminal can delete the line which the cursor is on, then this should be given as dl1; this is done only from the first position on the line to be deleted. Versions of il1 and dl1 which take a single parameter and insert or delete that many lines can be given as il and dl.

If the terminal has a settable scrolling region (like the vt100) the command to set this can be described with the csr capability, which takes two parameters: the top and bottom lines of the scrolling region. The cursor position is, alas, undefined after using this command.

It is possible to get the effect of insert or delete line using csr on a properly chosen region; the sc and rc (save and restore cursor) commands may be useful for ensuring that your synthesized insert/delete string does not move the cursor. (Note that the ncurses(3X) library does this synthesis automatically, so you need not compose insert/delete strings for an entry with csr).

Yet another way to construct insert and delete might be to use a combination of index with the memory-lock feature found on some terminals (like the HP-700/90 series, which however also has insert/delete).

Inserting lines at the top or bottom of the screen can also be done using ri or ind on many terminals without a true insert/delete line, and is often faster even on terminals with those features.

The Boolean non_dest_scroll_region should be set if each scrolling window is effectively a view port on a screen-sized canvas. To test for this capability, create a scrolling region in the middle of the screen, write something to the bottom line, move the cursor to the top of the region, and do ri followed by dl1 or ind. If the data scrolled off the bottom of the region by the ri re-appears, then scrolling is non-destructive. System V and X/Open Curses expect that ind, ri, indn, and rin will simulate destructive scrolling; their documentation cautions you not to define csr unless this is true. This curses implementation is more liberal and will do explicit erases after scrolling if ndsrc is defined.

If the terminal has the ability to define a window as part of memory, which all commands affect, it should be given as the parameterized string wind. The four parameters are the starting and ending lines in memory and the starting and ending columns in memory, in that order.

If the terminal can retain display memory above, then the da capability should be given; if display memory can be retained below, then db should be given. These indicate that deleting a line or scrolling may bring non-blank lines up from below or that scrolling back with ri may bring down non-blank lines.

โœจ Insert/Delete Character โœจ

There are two basic kinds of intelligent terminals with respect to insert/delete character which can be described using terminfo. The most common insert/delete character operations affect only the characters on the current line and shift characters off the end of the line rigidly. Other terminals, such as the Concept 100 and the Perkin Elmer Owl, make a distinction between typed and untyped blanks on the screen, shifting upon an insert or delete only to an untyped blank on the screen which is either eliminated, or expanded to two untyped blanks.

You can actually figure out which kind of terminal you're dealing with by clearing the screen and then typing text that's separated by cursor motions. Like, type โ€œabc defโ€ where the gap between abc and def is made with local cursor motions (not spaces). Then park the cursor before the abc and flip the terminal into insert mode. If typing characters makes the rest of the line shift rigidly and characters fall off the end โ€” congrats, your terminal doesn't distinguish between blanks and untyped positions ๐Ÿ’…. But if the abc slides over to the def and they both scoot along together around the end of the current line and onto the next as you insert, you've got the second type of terminal, and you should give the capability in, which stands for "insert null" ๐Ÿซถ.

So yeah, those are two logically separate attributes โ€” one is line versus multi-line insert mode, and the other is special treatment of untyped spaces โ€” but honestly we've never seen a terminal whose insert mode couldn't be described with just the single attribute.

Terminfo can describe both terminals that have an insert mode, and terminals that just send a simple sequence to open a blank position on the current line. Give smir as the sequence to get into insert mode. Give rmir as the sequence to leave insert mode. Now give ich1 as any sequence that needs to be sent just before sending the character to be inserted. Most terminals with a true insert mode won't give ich1; terminals that send a sequence to open a screen position should give it right here.

If your terminal has both, insert mode is usually preferable to ich1. Technically you shouldn't give both unless the terminal actually requires both to be used in combination. And accordingly, some non-curses applications get confused if both are present โ€” the symptom is doubled characters in an update that's using insert ๐Ÿ˜ญ. This requirement is rare now: most ich sequences don't require a previous smir, and most smir insert modes don't require ich1 before each character. So the new curses actually assumes this is the case and uses either rmir/smir or ich/ich1 as appropriate (but not both). If you've gotta write an entry that'll be used under new curses for a terminal old enough to need both, put the rmir/smir sequences inside ich1.

If post insert padding is needed, give it as a number of milliseconds in ip (a string option, yes really). Any other sequence that might need to be sent after inserting a single character can also go in ip. If your terminal needs both to be placed into an "insert mode" and a special code before each inserted character, then both smir/rmir and ich1 can be given, and both will be used. The ich capability, with one parameter, n, will repeat the effects of ich1 n times.

If padding is necessary between characters typed while not in insert mode, give this as a number of milliseconds padding in rmp.

It's occasionally necessary to move around while in insert mode so you can delete characters on the same line (for example, if there's a tab after the insertion position). If your terminal allows motion while in insert mode you can give the capability mir to speed up inserting in this case. Omitting mir will affect only speed. Some terminals (notably Datamedia's) must not have mir because of the way their insert mode works ๐Ÿ‘€.

Finally, you can specify dch1 to delete a single character, dch with one parameter, n, to delete n characters, and delete mode by giving smdc and rmdc to enter and exit delete mode (any mode the terminal needs to be placed in for dch1 to work).

A command to erase n characters โ€” equivalent to outputting n blanks without moving the cursor โ€” can be given as ech with one parameter.


โœจ Highlighting, Underlining, and Visible Bells โœจ

If your terminal has one or more kinds of display attributes, those can be represented a bunch of different ways. You should pick one display form as standout mode โ€” something that's a good, high contrast, easy-on-the-eyes format for highlighting error messages and other attention getters ๐Ÿ’–. (If you get to choose, reverse video plus half-bright is good, or reverse video alone.) The sequences to enter and exit standout mode are given as smso and rmso, respectively. If the code to change into or out of standout mode leaves one or even two blank spaces on the screen โ€” like the TVI 912 and Teleray 1061 do โ€” then xmc should be given to tell how many spaces are left.

Codes to begin underlining and end underlining can be given as smul and rmul respectively. If the terminal has a code to underline the current character and move the cursor one space to the right, like the Microterm Mime does, this can be given as uc.

Other capabilities to enter various highlighting modes include blink (blinking), bold (bold or extra bright), dim (dim or half-bright), invis (blanking or invisible text), prot (protected), rev (reverse video), sgr0 (turn off all attribute modes), smacs (enter alternate character set mode) and rmacs (exit alternate character set mode). Turning on any of these modes singly may or may not turn off other modes. No cap, it's a whole vibe.

If there's a sequence to set arbitrary combinations of modes, this should be given as sgr (set attributes), taking 9 parameters. Each parameter is either zero (0) or nonzero, depending on whether the corresponding attribute is on or off. The 9 parameters, in order, are: standout, underline, reverse, blink, dim, bold, blank, protect, alternate character set. Not all modes need be supported by sgr โ€” only those for which corresponding separate attribute commands exist.

For example, the DEC vt220 supports most of the modes ๐Ÿ‘‘:

  • none โ€” none โ€” \E[0m
  • p1 โ€” standout โ€” \E[0;1;7m
  • p2 โ€” underline โ€” \E[0;4m
  • p3 โ€” reverse โ€” \E[0;7m
  • p4 โ€” blink โ€” \E[0;5m
  • p5 โ€” dim โ€” not available
  • p6 โ€” bold โ€” \E[0;1m
  • p7 โ€” invis โ€” \E[0;8m
  • p8 โ€” protect โ€” not used
  • p9 โ€” altcharset โ€” ^O (off) ^N (on)

We begin each escape sequence by turning off any existing modes, since there's no quick way to determine whether they're active. Standout is set up to be the combination of reverse and bold. The vt220 terminal has a protect mode, though it's not commonly used in sgr because it protects characters on the screen from the host's erasures. The altcharset mode is also different โ€” it's either ^O or ^N, depending on whether it's off or on. If all modes are turned on, the resulting sequence is \E[0;1;4;5;7;8m^N.

Some sequences are common to different modes. For example, ;7 is output when either p1 or p3 is true โ€” that is, if either standout or reverse modes are turned on.

Writing out all the above sequences, along with their dependencies, gives you this ๐Ÿ‘‡

Sequence   When to Output      terminfo Translation
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
\E[0       always              \E[0
;1         if p1 or p6         %?%p1%p6%|%t;1%;
;4         if p2               %?%p2%|%t;4%;
;5         if p4               %?%p4%|%t;5%;
;7         if p1 or p3         %?%p1%p3%|%t;7%;
;8         if p7               %?%p7%|%t;8%;
m          always              m
^N or ^O   if p9 ^N, else ^O   %?%p9%t^N%e^O%;

Putting it all together into the sgr sequence gives:

sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p4%t;5%;
    %?%p1%p3%|%t;7%;%?%p7%t;8%;m%?%p9%t\016%e\017%;,

Remember: if you specify sgr, you must also specify sgr0. Also, some implementations rely on sgr being given if sgr0 is. Not all terminfo entries necessarily have an sgr string though โ€” many terminfo entries are derived from termcap entries which have no sgr string. The only drawback to adding an sgr string is that termcap also assumes that sgr0 does not exit alternate character set mode ๐Ÿซ .

Terminals with the "magic cookie" glitch (xmc) deposit special "cookies" when they receive mode-setting sequences, which affect the display algorithm rather than having extra bits for each character. Some terminals, like the HP 2621, automatically leave standout mode when they move to a new line or the cursor is addressed. Programs using standout mode should exit standout mode before moving the cursor or sending a newline โ€” unless the msgr capability, which asserts that it's safe to move in standout mode, is present.

If the terminal has a way of flashing the screen to indicate an error quietly (a bell replacement) then this can be given as flash; it must not move the cursor.

If the cursor needs to be made more visible than normal when it's not on the bottom line (to turn, for example, a non-blinking underline into an easier-to-find block or blinking underline) give this sequence as cvvis. If there's a way to make the cursor completely invisible, give that as civis. The capability cnorm should be given, which undoes the effects of both of these modes.

If your terminal correctly generates underlined characters (with no special codes needed) even though it doesn't overstrike, then you should give the capability ul. If a character overstriking another leaves both characters on the screen, specify the capability os. If overstrikes are erasable with a blank, then this should be indicated by giving eo.


๐Ÿ”‘ Keypad and Function Keys ๐Ÿ”‘

If the terminal has a keypad that transmits codes when the keys are pressed, this info can be given. But note: it is not possible to handle terminals where the keypad only works in local โ€” that applies, for example, to the unshifted HP 2621 keys ๐Ÿ™ˆ. If the keypad can be set to transmit or not transmit, give these codes as smkx and rmkx. Otherwise the keypad is assumed to always transmit.

The codes sent by the left arrow, right arrow, up arrow, down arrow, and home keys can be given as kcub1, kcuf1, kcuu1, kcud1, and khome respectively. If there are function keys like f0, f1, ..., f10, the codes they send can be given as kf0, kf1, ..., kf10. If these keys have labels other than the default f0 through f10, the labels can be given as lf0, lf1, ..., lf10.

The codes transmitted by certain other special keys can be given:

  • kll (home down),
  • kbs (backspace),
  • ktbc (clear all tabs),
  • kctab (clear the tab stop in this column),
  • kclr (clear screen or erase key),
  • kdch1 (delete character),
  • kdl1 (delete line),
  • krmir (exit insert mode),

okay so picking right back up with the rest of the key-capability lineup, bestie:

  • kel โ€” clear to end of line,
  • ked โ€” clear to end of screen,
  • kich1 โ€” insert character or enter insert mode,
  • kil1 โ€” insert line,
  • knp โ€” next page,
  • kpp โ€” previous page,
  • kind โ€” scroll forward/down,
  • kri โ€” scroll backward/up,
  • khts โ€” set a tab stop in this column.

In addition, if the keypad has a 3 by 3 array of keys including the four arrow keys, the other five keys can be given as ka1, ka3, kb2, kc1, and kc3. These keys are useful when the effects of a 3 by 3 directional pad are needed. โœจ

Strings to program function keys can be given as pfkey, pfloc, and pfx. A string to program screen labels should be specified as pln. Each of these strings takes two parameters: the function key number to program (from 0 to 10) and the string to program it with. Function key numbers out of this range may program undefined keys in a terminal dependent manner. The difference between the capabilities is that pfkey causes pressing the given key to be the same as the user typing the given string; pfloc causes the string to be executed by the terminal in local; and pfx causes the string to be transmitted to the computer.

The capabilities nlab, lw and lh define the number of programmable screen labels and their width and height. If there are commands to turn the labels on and off, give them in smln and rmln. smln is normally output after one or more pln sequences to make sure that the change becomes visible. ๐Ÿ’…

โœจ Tabs and Initialization โœจ

A few capabilities are used only to manage tab stops.

  • If the terminal has hardware tabs, specify the character sequence that advances to the next tab stop as the value of the tab (ht) string capability (usually Control+I).
  • Specify a character sequence that retreats (moves leftward) to the preceding tab stop as the value of the back_tab (cbt) string capability.
By convention, if the terminal modes are configured such that tabs are expanded by the host rather than terminal, applications should not employ the tab (ht) or back_tab (cbt) capabilities even if they are present, since the user may not have the tab stops properly set.
  • If the terminal has hardware tab stops that are set at every n character cells when the terminal is powered up, specify n as the value of the numeric capability init_tabs (it).

The tset and โ€œtput initโ€ commands interpret the presence of the init_tabs (it) capability as implying that the terminal is responsible for tab stop expansion as well as an instruction to set the tab stops to its value. If the terminal has tab stops that can be saved in non-volatile memory, its terminfo type description can assume that they are properly set.

Other capabilities include

  • is1, is2, and is3 โ€” initialization strings for the terminal,
  • iprog โ€” the path name of a program to be run to initialize the terminal,
  • if โ€” the name of a file containing long initialization strings.

These strings are expected to set the terminal into modes consistent with the rest of the terminfo description. They are normally sent to the terminal, by the init option of the tput program, each time the user logs in. They will be printed in the following order:

  1. run the program iprog
  2. output is1 and is2
  3. set the margins using mgc or smglp and smgrp or smgl and smgr
  4. set tabs using tbc and hts
  5. print the file if
  6. and finally output is3.

Most initialization is done with is2. Special terminal modes can be set up without duplicating strings by putting the common sequences in is2 and special cases in is1 and is3. ๐Ÿซถ

A set of sequences that does a harder reset from a totally unknown state can be given as rs1, rs2, rf, and rs3, analogous to is1, is2, if, and is3 respectively. These strings are output by the reset option of tput, or by the reset program (an alias of tset), which is used when the terminal gets into a wedged state. Commands are normally placed in rs1, rs2, rs3, and rf only if they produce annoying effects on the screen and are not necessary when logging in. For example, the command to set the vt100 into 80-column mode would normally be part of is2, but it causes an annoying glitch of the screen and is not normally needed since the terminal is usually already in 80-column mode.

The reset program writes strings including iprog, etc., in the same order as the init program, using rs1, etc., instead of is1, etc. If any of rs1, rs2, rs3, or rf reset capability strings are missing, the reset program falls back upon the corresponding initialization capability string.

If there are commands to set and clear tab stops, they can be given as tbc (clear all tab stops) and hts (set a tab stop in the current column of every line). If a more complex sequence is needed to set the tabs than can be described by this, the sequence can be placed in is2 or if.

The tput reset command uses the same capability strings as the reset command, although the two programs (tput and reset) provide different command-line options.

In practice, these terminfo capabilities are not often used in initialization of tabs (though they are required for the tabs program):

  • Almost all hardware terminals (at least those which supported tabs) initialized those to every eight columns:

The only exception was the AT&T 2300 series, which set tabs to every five columns.

  • In particular, developers of the hardware terminals which are commonly used as models for modern terminal emulators provided documentation demonstrating that eight columns were the standard.
  • Because of this, the terminal initialization programs tput and tset use the tbc (clear_all_tabs) and hts (set_tab) capabilities directly only when the it (init_tabs) capability is set to a value other than eight. ๐ŸŒˆ

๐ŸŒธ Delays and Padding ๐ŸŒธ

Many older and slower terminals do not support either XON/XOFF or DTR handshaking, including hard copy terminals and some very archaic CRTs (including, for example, DEC VT100s). These may require padding characters after certain cursor motions and screen changes.

If the terminal uses xon/xoff handshaking for flow control (that is, it automatically emits ^S back to the host when its input buffers are close to full), set xon. This capability suppresses the emission of padding. You can also set it for memory-mapped console devices effectively that do not have a speed limit. Padding information should still be included so that routines can make better decisions about relative costs, but actual pad characters will not be transmitted.

If pb (padding baud rate) is given, padding is suppressed at baud rates below the value of pb. If the entry has no padding baud rate, then whether padding is emitted or not is completely controlled by xon.

If the terminal requires other than a null (zero) character as a pad, then this can be given as pad. Only the first character of the pad string is used. ๐ŸŽ€

๐Ÿฆ‹ Status Lines ๐Ÿฆ‹

Some terminals have an extra โ€œstatus lineโ€ which is not normally used by software (and thus not counted in the terminal's lines capability).

The simplest case is a status line which is cursor-addressable but not part of the main scrolling region on the screen; the Heathkit H19 has a status line of this kind, as would a 24-line VT100 with a 23-line scrolling region set up on initialization. This situation is indicated by the hs capability.

Some terminals with status lines need special sequences to access the status line. These may be expressed as a string with single parameter tsl which takes the cursor to a given zero-origin column on the status line. The capability fsl must return to the main-screen cursor positions before the last tsl. You may need to embed the string values of sc (save cursor) and rc (restore cursor) in tsl and fsl to accomplish this.

The status line is normally assumed to be the same width as the width of the terminal. If this is untrue, you can specify it with the numeric capability wsl.

A command to erase or blank the status line may be specified as dsl.

The Boolean capability eslok specifies that escape sequences, tabs, etc., work ordinarily in the status line.

The ncurses implementation does not yet use any of these capabilities. They are documented here in case they ever become important. ๐Ÿ’€

๐ŸŽจ Line Graphics ๐ŸŽจ

Many terminals have alternate character sets useful for forms-drawing. Terminfo and curses have built-in support for most of the drawing characters supported by the VT100, with some characters from the AT&T 4410v1 added. This alternate character set may be specified by the acsc capability. ๐Ÿ–๏ธโœจ

okay so we're picking up mid-table and honestly this is the part where it gets good ๐Ÿ’… here is the rest of the acsc table โ€” every name, its value, the character it maps to, the ASCII fallback, and what the glyph actually is:

  • ACS_RARROW โ€” value 0x2b โ€” symbol + โ€” ASCII fallback > โ€” arrow pointing right
  • ACS_LARROW โ€” value 0x2c โ€” symbol , โ€” ASCII fallback < โ€” arrow pointing left
  • ACS_UARROW โ€” value 0x2d โ€” symbol - โ€” ASCII fallback ^ โ€” arrow pointing up
  • ACS_DARROW โ€” value 0x2e โ€” symbol . โ€” ASCII fallback v โ€” arrow pointing down
  • ACS_BLOCK โ€” value 0x30 โ€” symbol 0 โ€” ASCII fallback # โ€” solid square block
  • ACS_DIAMOND โ€” value 0x60 โ€” symbol ` โ€” ASCII fallback + โ€” diamond
  • ACS_CKBOARD โ€” value 0x61 โ€” symbol a โ€” ASCII fallback : โ€” checker board (stipple)
  • ACS_DEGREE โ€” value 0x66 โ€” symbol f โ€” ASCII fallback \ โ€” degree symbol
  • ACS_PLMINUS โ€” value 0x67 โ€” symbol g โ€” ASCII fallback # โ€” plus/minus
  • ACS_BOARD โ€” value 0x68 โ€” symbol h โ€” ASCII fallback # โ€” board of squares
  • ACS_LANTERN โ€” value 0x69 โ€” symbol i โ€” ASCII fallback # โ€” lantern symbol
  • ACS_LRCORNER โ€” value 0x6a โ€” symbol j โ€” ASCII fallback + โ€” lower right corner
  • ACS_URCORNER โ€” value 0x6b โ€” symbol k โ€” ASCII fallback + โ€” upper right corner
  • ACS_ULCORNER โ€” value 0x6c โ€” symbol l โ€” ASCII fallback + โ€” upper left corner
  • ACS_LLCORNER โ€” value 0x6d โ€” symbol m โ€” ASCII fallback + โ€” lower left corner
  • ACS_PLUS โ€” value 0x6e โ€” symbol n โ€” ASCII fallback + โ€” large plus or crossover
  • ACS_S1 โ€” value 0x6f โ€” symbol o โ€” ASCII fallback ~ โ€” scan line 1
  • ACS_S3 โ€” value 0x70 โ€” symbol p โ€” ASCII fallback - โ€” scan line 3
  • ACS_HLINE โ€” value 0x71 โ€” symbol q โ€” ASCII fallback - โ€” horizontal line
  • ACS_S7 โ€” value 0x72 โ€” symbol r โ€” ASCII fallback - โ€” scan line 7
  • ACS_S9 โ€” value 0x73 โ€” symbol s โ€” ASCII fallback _ โ€” scan line 9
  • ACS_LTEE โ€” value 0x74 โ€” symbol t โ€” ASCII fallback + โ€” tee pointing right
  • ACS_RTEE โ€” value 0x75 โ€” symbol u โ€” ASCII fallback + โ€” tee pointing left
  • ACS_BTEE โ€” value 0x76 โ€” symbol v โ€” ASCII fallback + โ€” tee pointing up
  • ACS_TTEE โ€” value 0x77 โ€” symbol w โ€” ASCII fallback + โ€” tee pointing down
  • ACS_VLINE โ€” value 0x78 โ€” symbol x โ€” ASCII fallback | โ€” vertical line
  • ACS_LEQUAL โ€” value 0x79 โ€” symbol y โ€” ASCII fallback < โ€” less-than-or-equal-to
  • ACS_GEQUAL โ€” value 0x7a โ€” symbol z โ€” ASCII fallback > โ€” greater-than-or-equal-to
  • ACS_PI โ€” value 0x7b โ€” symbol { โ€” ASCII fallback * โ€” greek pi
  • ACS_NEQUAL โ€” value 0x7c โ€” symbol | โ€” ASCII fallback ! โ€” not-equal
  • ACS_STERLING โ€” value 0x7d โ€” symbol } โ€” ASCII fallback f โ€” UK pound sign
  • ACS_BULLET โ€” value 0x7e โ€” symbol ~ โ€” ASCII fallback o โ€” bullet

and a few lil notes that apply to the table itself, bestie, don't skip these ๐Ÿซถ

  • X/Open Curses incorrectly states that the mapping for lantern is uppercase "I" โ€” but Unix implementations use the lowercase "i" mapping. so like, that's a whole documented lie in the spec ๐Ÿ˜ญ
  • The DEC VT100 implemented graphics using the alternate character set feature, temporarily switching modes and sending characters in the range 0x60 (96) to 0x7e (126) โ€” that's the acsc Value column up there, iykyk.
  • The AT&T terminal added graphics characters outside that range.

Some of the characters within the range do not match the VT100; presumably they were used in the AT&T terminal: board of squares replaces the VT100 newline symbol, while lantern symbol replaces the VT100 vertical tab symbol. The other VT100 symbols for control characters (horizontal tab, carriage return and line-feed) are not (re)used in curses.

The best way to define a new device's graphics set is to add a column to a copy of this table for your terminal, giving the character which (when emitted between smacs/rmacs switches) will be rendered as the corresponding graphic. Then read off the VT100/your terminal character pairs right to left in sequence โ€” these become the ACSC string. lowkey iconic method ngl ๐ŸŒธ

๐ŸŽจ Color Handling ๐ŸŽจ

The curses library functions init_pair and init_color manipulate the color pairs and colors (color values or indices, such as "1=red") discussed in this section โ€” see curs_color(3X) for the details on these and related functions.

Most color terminals are either "Tektronix-like" or "HP-like" in their approach to color management:

  • Tektronix-like terminals define a set of n colors (where n is usually 8), and can alter character-cell foreground and background colors independently, mixing them into nร—*n* color pairs. ANSI-standard terminals are Tektronix-like.
  • On HP-like terminals, the user must set up each color pair separately; foreground and background are not independently alterable. Up to m color pairs may be configured from 2ร—*m* different colors.

Some basic color management capabilities are independent of the color encoding method. The numeric capabilities max_colors (colors) and max_pairs (pairs) specify the maximum numbers of colors and color pairs that the device can display simultaneously. The orig_pair (op) ("original pair") string capability resets foreground and background colors to their default values for the terminal. The orig_colors (oc) ("original colors") string capability resets all colors or color pairs to their default values for the terminal. Some terminal types (including many PC terminal emulators) erase screen areas with the current background color rather than the power-up default background โ€” these should declare the Boolean capability back_color_erase (bce). ๐Ÿ–๏ธ

While the curses library works with color pairs (reflecting the inability of some devices to set foreground and background colors independently), there are separate capabilities for setting these features:

  • To change the current foreground or background color on a Tektronix-type terminal, use setaf (set ANSI foreground) and setab (set ANSI background) or setf (set foreground) and setb (set background). These take one parameter, the color number. The SVr4 documentation describes only setaf/setab; the XPG4 draft says that "If the terminal supports ANSI escape sequences to set background and foreground, they should be coded as setaf and setab, respectively."
  • If the terminal supports other escape sequences to set background and foreground, they should be coded as setf and setb, respectively. The vidputs and the refresh(3X) functions use the setaf and setab capabilities if they are defined.

The setaf/setab and setf/setb capabilities take a single numeric argument each. Argument values 0-7 of setaf/setab are portably defined as follows โ€” the middle column is the symbolic #define available in the header for the curses or ncurses libraries. The terminal hardware is free to map these as it likes, but the RGB values indicate normal locations in color space. โœจ

  • black โ€” COLOR_BLACK โ€” value 0 โ€” RGB 0, 0, 0
  • red โ€” COLOR_RED โ€” value 1 โ€” RGB max, 0, 0
  • green โ€” COLOR_GREEN โ€” value 2 โ€” RGB 0, max, 0
  • yellow โ€” COLOR_YELLOW โ€” value 3 โ€” RGB max, max, 0
  • blue โ€” COLOR_BLUE โ€” value 4 โ€” RGB 0, 0, max
  • magenta โ€” COLOR_MAGENTA โ€” value 5 โ€” RGB max, 0, max
  • cyan โ€” COLOR_CYAN โ€” value 6 โ€” RGB 0, max, max
  • white โ€” COLOR_WHITE โ€” value 7 โ€” RGB max, max, max

The argument values of setf/setb historically correspond to a different mapping, i.e.:

  • black โ€” COLOR_BLACK โ€” value 0 โ€” RGB 0, 0, 0
  • blue โ€” COLOR_BLUE โ€” value 1 โ€” RGB 0, 0, max
  • green โ€” COLOR_GREEN โ€” value 2 โ€” RGB 0, max, 0
  • cyan โ€” COLOR_CYAN โ€” value 3 โ€” RGB 0, max, max
  • red โ€” COLOR_RED โ€” value 4 โ€” RGB max, 0, 0
  • magenta โ€” COLOR_MAGENTA โ€” value 5 โ€” RGB max, 0, max
  • yellow โ€” COLOR_YELLOW โ€” value 6 โ€” RGB max, max, 0
  • white โ€” COLOR_WHITE โ€” value 7 โ€” RGB max, max, max
It is important to not confuse the two sets of color capabilities; otherwise red/blue will be interchanged on the display. like, your red will literally be blue and you'll be staring at your terminal like ๐Ÿ˜ญ๐Ÿ’€

On an HP-like terminal, use scp with a color pair number parameter to set which color pair is current.

Some terminals allow the color values to be modified:

  • On a Tektronix-like terminal, the capability ccc may be present to indicate that colors can be modified. If so, the initc capability will take a color number (0 to colors - 1) and three more parameters which describe the color. These three parameters default to being interpreted as RGB (Red, Green, Blue) values. If the Boolean capability hls is present, they are instead as HLS (Hue, Lightness, Saturation) indices. The ranges are terminal-dependent.
  • On an HP-like terminal, initp may give a capability for changing a color pair value. It will take seven parameters: a color pair number (0 to max_pairs - 1), and two triples describing first background and then foreground colors. These parameters must be (Red, Green, Blue) or (Hue, Lightness, Saturation) depending on hls.

On some color terminals, colors collide with highlights โ€” iconic messiness honestly ๐Ÿ™ˆ You can register these collisions with the ncv capability. This is a bit mask of attributes not to be used when colors are enabled. The correspondence with the attributes understood by curses is as follows:

  • A_STANDOUT โ€” bit 0 โ€” decimal 1 โ€” set by sgr
  • A_UNDERLINE โ€” bit 1 โ€” decimal 2 โ€” set by sgr
  • A_REVERSE โ€” bit 2 โ€” decimal 4 โ€” set by sgr
  • A_BLINK โ€” bit 3 โ€” decimal 8 โ€” set by sgr
  • A_DIM โ€” bit 4 โ€” decimal 16 โ€” set by sgr
  • A_BOLD โ€” bit 5 โ€” decimal 32 โ€” set by sgr
  • A_INVIS โ€” bit 6 โ€” decimal 64 โ€” set by sgr
  • A_PROTECT โ€” bit 7 โ€” decimal 128 โ€” set by sgr
  • A_ALTCHARSET โ€” bit 8 โ€” decimal 256 โ€” set by sgr
  • A_HORIZONTAL โ€” bit 9 โ€” decimal 512 โ€” set by sgr1
  • A_LEFT โ€” bit 10 โ€” decimal 1024 โ€” set by sgr1
  • A_LOW โ€” bit 11 โ€” decimal 2048 โ€” set by sgr1
  • A_RIGHT โ€” bit 12 โ€” decimal 4096 โ€” set by sgr1
  • A_TOP โ€” bit 13 โ€” decimal 8192 โ€” set by sgr1
  • A_VERTICAL โ€” bit 14 โ€” decimal 16384 โ€” set by sgr1
  • A_ITALIC โ€” bit 15 โ€” decimal 32768 โ€” set by sitm

For example, on many IBM PC consoles, the underline attribute collides with the foreground color blue and is not available in color mode. These should have an ncv capability of 2. ๐ŸŽ€

SVr4 curses does nothing with ncv โ€” ncurses recognizes it and optimizes the output in favor of colors. slay for ncurses honestly ๐Ÿ‘‘

๐Ÿงฉ Miscellaneous ๐Ÿงฉ

If the terminal requires other than a null (zero) character as a pad, then this can be given as pad. Only the first character of the pad string is used. If the terminal does not have a pad character, specify npc. Note that ncurses implements the termcap-compatible PC variable; though the application may set this value to something other than a null, ncurses will test npc first and use napms if the terminal has no pad character. ๐Ÿฆ‹

So if your terminal can move up or down half a line, thatโ€™s hu (half-line up) and hd (half-line down) ๐Ÿ’… bestie, this is mainly for superscripts and subscripts on hard-copy terminals. And if your hard-copy terminal can eject to the next page (form feed), you give that as ff (usually control/L) ๐ŸŽ€.

If thereโ€™s a command to repeat a given character a given number of times (to save time transmitting a large number of identical characters), thatโ€™s the parameterized string rep โœจ. The first parameter is the character to be repeated, and the second is the number of times to repeat it. So tparm(repeat_char, 'x', 10) is literally the same as xxxxxxxxxx ๐Ÿ‘‘

If the terminal has a settable command character, like the TEKTRONIX 4025, thatโ€™s cmdch ๐Ÿฆ‹. A prototype command character is chosen and used in all capabilities, and that character is given in the cmdch capability to identify it. The following convention is supported on some Unix systems: the environment is searched for a CC variable, and if itโ€™s found, all occurrences of the prototype character are replaced with the character in the environment variable ๐Ÿซถ.

Terminal descriptions that do not represent a specific kind of known terminal โ€” think switch, dialup, patch, and network โ€” should include the gn (generic) capability so programs can complain that they do not know how to talk to the terminal ๐Ÿ˜ญ. (This capability does not apply to virtual terminal descriptions for which the escape sequences are known.)

If the terminal has a โ€œmeta keyโ€ that acts as a shift key, setting the 8th bit of any character transmitted, thatโ€™s km ๐Ÿ”ฅ. Otherwise, software will assume the 8th bit is parity and it will usually be cleared. If strings exist to turn this โ€œmeta modeโ€ on and off, they can be given as smm and rmm โญ.

If the terminal has more lines of memory than will fit on the screen at once, the number of lines of memory can be indicated with lm ๐ŸŒธ. A value of lm#0 indicates that the number of lines is not fixed, but that there is still more memory than fits on the screen ๐Ÿงš.

If the terminal is one of those supported by the Unix virtual terminal protocol, the terminal number can be given as vt ๐Ÿ’œ.

Media copy strings that control an auxiliary printer connected to the terminal can be given as mc0: print the contents of the screen, mc4: turn off the printer, and mc5: turn on the printer ๐Ÿ–จ๏ธโœจ. When the printer is on, all text sent to the terminal will be sent to the printer. It is undefined whether the text is also displayed on the terminal screen when the printer is on ๐Ÿ˜ญ. A variation mc5p takes one parameter, and leaves the printer on for as many characters as the value of the parameter, then turns the printer off. The parameter should not exceed 255 ๐Ÿ’€. All text, including mc4, is transparently passed to the printer while an mc5p is in effect.

๐Ÿ’€ Glitches and Brain Damage ๐Ÿ’€

Hazeltine terminals, which do not allow ~ characters to be displayed, should indicate hz ๐Ÿ™ˆ.

Terminals which ignore a line-feed immediately after an am wrap, such as the Concept and vt100, should indicate xenl โญ.

If el is required to get rid of standout (instead of merely writing normal text on top of it), xhp should be given ๐Ÿ’….

Teleray terminals, where tabs turn all characters moved over to blanks, should indicate xt (destructive tabs) ๐Ÿ”ฅ. Note: the variable indicating this is now dest_tabs_magic_smso; in older versions, it was teleray_glitch. This glitch is also taken to mean that it is not possible to position the cursor on top of a โ€œmagic cookieโ€, that to erase standout mode it is instead necessary to use delete and insert line. The ncurses implementation ignores this glitch ๐Ÿ‘€.

The Beehive Superbee, which is unable to correctly transmit the escape or control/C characters, has xsb, indicating that the f1 key is used for escape and f2 for control/C ๐Ÿ. (Only certain Superbees have this problem, depending on the ROM.) Note that in older terminfo versions, this capability was called beehive_glitch; it is now no_esc_ctl_c ๐Ÿ’–.

Other specific terminal problems may be corrected by adding more capabilities of the form xx ๐ŸŽ€.

๐Ÿงจ Pitfalls of Long Entries ๐Ÿงจ

Long terminfo entries are unlikely to be a problem; to date, no entry has even approached terminfoโ€™s 4096-byte string-table maximum ๐Ÿฆ‹. Unfortunately, the termcap translations are much more strictly limited (to 1023 bytes), so termcap translations of long terminfo entries can cause problems ๐Ÿ˜ญ.

The man pages for 4.3BSD and older versions of tgetent instruct the user to allocate a 1024-byte buffer for the termcap entry. The entry gets null-terminated by the termcap library, so that makes the maximum safe length for a termcap entry 1k-1 (1023) bytes ๐Ÿ’€. Depending on what the application and the termcap library being used does, and where in the termcap file the terminal type that tgetent is searching for is, several bad things can happen:

  • some termcap libraries print a warning message,
  • some exit if they find an entry thatโ€™s longer than 1023 bytes,
  • some neither exit nor warn, doing nothing useful, and
  • some simply truncate the entries to 1023 bytes.

Some application programs allocate more than the recommended 1K for the termcap entry; others do not ๐Ÿ™ˆ.

Each termcap entry has two important sizes associated with it: before tc expansion, and after tc expansion โœจ. tc is the capability that tacks on another termcap entry to the end of the current one, to add on its capabilities. If a termcap entry does not use the tc capability, then of course the two lengths are the same ๐Ÿซถ.

The โ€œbefore tc expansionโ€ length is the most important one, because it affects more than just users of that particular terminal ๐Ÿ‘‘. This is the length of the entry as it exists in /etc/termcap, minus the backslash-newline pairs, which tgetent strips out while reading it. Some termcap libraries strip off the final newline, too (GNU termcap does not) ๐ŸŽ€. Now suppose:

  • a termcap entry before expansion is more than 1023 bytes long,
  • and the application has only allocated a 1k buffer,
  • and the termcap library (like the one in BSD/OS 1.1 and GNU) reads the whole entry into the buffer, no matter what its length, to see if it is the entry it wants,
  • and tgetent is searching for a terminal type that either is the long entry, appears in the termcap file after the long entry, or does not appear in the file at all (so that tgetent has to search the whole termcap file).

Then tgetent will overwrite memory, perhaps its stack, and probably core dump the program ๐Ÿ’€๐Ÿ˜ญ. Programs like telnet are particularly vulnerable; modern telnets pass along values like the terminal type automatically. The results are almost as undesirable with a termcap library, like SunOS 4.1.3 and Ultrix 4.4, that prints warning messages when it reads an overly long termcap entry. If a termcap library truncates long entries, like OSF/1 3.0, it is immune to dying here but will return incorrect data for the terminal ๐Ÿ™ˆ.

The โ€œafter tc expansionโ€ length will have a similar effect to the above, but only for people who actually set TERM to that terminal type, since tgetent only does tc expansion once it has found the terminal type it was looking for, not while searching ๐Ÿ”ฅ.

In summary, a termcap entry that is longer than 1023 bytes can cause, on various combinations of termcap libraries and applications, a core dump, warnings, or incorrect operation ๐Ÿ˜ญ. If it is too long even before tc expansion, it will have this effect even for users of some other terminal types and users whose TERM variable does not have a termcap entry ๐Ÿ’….

When in -C (translate to termcap) mode, the ncurses implementation of tic(1M) issues warning messages when the pre-tc length of a termcap translation is too long. The -c (check) option also checks resolved (after tc expansion) lengths โญ.

๐Ÿ“ FILES ๐Ÿ“

  • /usr/share/terminfo โ€” compiled terminal description database directory ๐ŸŽ€

โœจ EXTENSIONS โœจ

Searching for terminal descriptions in $HOME/.terminfo and TERMINFO_DIRS is not supported by older implementations ๐Ÿฆ‹.

Some SVr4 curses implementations, and all previous to SVr4, do not interpret the %A and %O operators in parameter strings ๐Ÿ’….

SVr4/XPG4 do not specify whether msgr licenses movement while in an alternate-character-set mode (such modes may, among other things, map CR and NL to characters that do not trigger local motions) ๐Ÿ‘€. The ncurses implementation ignores msgr in ALTCHARSET mode. This raises the possibility that an XPG4 implementation making the opposite interpretation may need terminfo entries made for ncurses to have msgr turned off ๐Ÿ˜ญ.

The ncurses library handles insert-character and insert-character modes in a slightly non-standard way to get better update efficiency โœจ. See the Insert/Delete Character subsection above.

The parameter substitutions for set_clock and display_clock are not documented in SVr4 or X/Open Curses. They are deduced from the documentation for the AT&T 505 terminal ๐Ÿซถ.

Be careful assigning the kmous capability ๐Ÿ’€. The ncurses library wants to interpret it as KEY_MOUSE, for use by terminals and emulators like xterm that can return mouse-tracking information in the keyboard-input stream ๐Ÿญ.

X/Open Curses does not mention italics. Portable applications must assume that numeric capabilities are signed 16-bit values โญ. This includes the no_color_video (ncv) capability. The 32768 mask value used for italics with ncv can be confused with an absent or canceled ncv ๐Ÿ˜ญ. If italics should work with colors, then the ncv value must be specified, even if it is zero ๐Ÿ’….

Different commercial ports of terminfo and curses support different subsets of X/Open Curses and (in some cases) different extensions. Here is a summary, accurate as of October 1995, after which the commercial Unix market contracted and lost diversity ๐ŸŽ€:

  • SVr4, Solaris, and ncurses โ€” support all SVr4 capabilities ๐Ÿ‘‘
  • IRIX โ€” supports the SVr4 set and adds one undocumented extended string capability (set_pglen) ๐Ÿฆ‹
  • SVr1 and Ultrix โ€” support a restricted subset of terminfo capabilities. The Booleans end with xon_xoff; the numerics with width_status_line; and the strings with prtr_non โœจ
  • HP/UX โ€” supports the SVr1 subset, plus the SVr[234] numerics num_labels, label_height, label_width, plus function keys 11 through 63, plus plab_norm, label_on, and label_off, plus a number of incompatible string table extensions ๐Ÿ’…
  • AIX โ€” supports the SVr1 subset, plus function keys 11 through 63, plus a number of incompatible string table extensions ๐Ÿ”ฅ
  • OSF/1 โ€” supports both the SVr4 set and the AIX extensions ๐ŸŒˆ

๐Ÿšจ PORTABILITY ๐Ÿšจ

Okay bestie, listen, this is the part where I hold your face gently and say do not do the thing:

Do not count on compiled (binary) terminfo entries being portable between commercial Unix systems. Periodt. ๐Ÿ’€

Like, fr fr, do not assume that a binary terminfo entry you compiled on one box is gonna just vibe on another vendor's machine, because it will not, and you will be sad.

Here's the tea ๐Ÿต โ€” at least two implementations of terminfo (the ones from HP-UX and AIX) diverged from the ones in other System V Unices after SVr1. The way they did it? They added extension capabilities to the string table that โ€” in the binary format โ€” collide with subsequent System V and X/Open Curses extensions. Collide!! ๐Ÿ’ฅ Like two girls showing up to the same party in the same dress, except the dress is a binary struct and the party is your terminal.

So: compile locally, ship source, don't ship binaries across vendors. That's the whole vibe check. ๐Ÿซถ


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

Shoutout to the icons who made this whole thing happen, no cap:

  • Zeyd M. Ben-Halim
  • Eric S. Raymond
  • Thomas E. Dickey

And based on pcurses by Pavel Curtis โ€” respect the OGs, iykyk. ๐ŸŽ€


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

Go read these next, they're literally all besties with this page:


Okay that's the whole page, we're done, you ate that. ๐Ÿ’…โœจ This masterpiece is brought to you by ncurses 6.6, dated 2025-08-16, and it's page terminfo(5) in case you forgot where you were. Go forth and be iconic with your terminals, bestie. ๐Ÿฆ‹๐Ÿ’–๐ŸŒธ

๐Ÿ“ฆ where this page comes from
  • alpine 3.24: ncurses-doc 6.6_p20260516-r0 ยท X11
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms