TerminfoSourceTyped access to terminfo capabilities.
Terminfo loads entries from the system terminfo database and exposes each capability as a typed token. The cap GADT encodes the return type of every capability so that get is type-safe at compile time.
Terminology.
xterm-256color).t) is an immutable, in-memory representation of one entry. match Terminfo.load () with
| Error (`Parse_error msg) ->
prerr_endline ("terminfo parse error: " ^ msg)
| Error `Not_found -> prerr_endline "no terminfo entry"
| Ok ti -> (
Option.iter print_string (Terminfo.get ti Terminfo.Clear_screen);
(match Terminfo.get ti Terminfo.Cursor_position with
| Some goto -> print_string (goto (5, 10))
| None -> ());
match Terminfo.get ti Terminfo.Has_colors with
| Some true -> print_endline "colors"
| _ -> print_endline "monochrome")type _ cap = | Auto_left_margin : bool capAutomatic left margins (bw).
| Auto_right_margin : bool capAutomatic right margins (am).
| Back_color_erase : bool capScreen erased with background color (bce).
| Can_change : bool capTerminal can redefine existing colors (ccc).
| Eat_newline_glitch : bool capNewline ignored after rightmost column (xenl).
| Has_colors : bool capTerminal supports colors. Synthesized: true iff the numeric colors capability is present and greater than 0. Always yields Some true or Some false.
See also Max_colors.
| Has_meta_key : bool capTerminal has a meta key (km).
| Insert_null_glitch : bool capInsert mode distinguishes nulls (in).
| Move_insert_mode : bool capSafe to move while in insert mode (mir).
| Move_standout_mode : bool capSafe to move while in standout mode (msgr).
| Over_strike : bool capTerminal can overstrike (os).
| Transparent_underline : bool capUnderline character overstrikes (ul).
| Xon_xoff : bool capTerminal uses xon/xoff handshaking (xon).
| Columns : int capNumber of columns in a line (cols).
| Lines : int capNumber of lines on screen (lines).
| Max_colors : int cap| Max_pairs : int capMaximum number of color pairs (pairs).
| Max_attributes : int capMaximum combined attributes (ma).
| Init_tabs : int capInitial tab stop spacing (it).
| Virtual_terminal : int capVirtual terminal number (vt).
| Bell : string capAudible bell (bel).
| Carriage_return : string capCarriage return (cr).
| Clear_screen : string capClear screen and home cursor (clear).
| Clear_to_eol : string capClear to end of line (el).
| Clear_to_eos : string capClear to end of screen (ed).
| Cursor_down : string capMove cursor down one line (cud1).
| Cursor_home : string capHome cursor to upper-left corner (home).
| Cursor_invisible : string capMake cursor invisible (civis).
| Cursor_left : string capMove cursor left one character (cub1).
| Cursor_normal : string capRestore cursor to normal visibility (cnorm).
| Cursor_right : string capMove cursor right one character (cuf1).
| Cursor_up : string capMove cursor up one line (cuu1).
| Cursor_visible : string capMake cursor very visible (cvvis).
| Delete_character : string capDelete one character (dch1).
| Delete_line : string capDelete one line (dl1).
| Enter_alt_charset : string capStart alternate character set (smacs).
| Enter_blink_mode : string capTurn on blinking (blink).
| Enter_bold_mode : string capTurn on bold (bold).
| Enter_dim_mode : string capTurn on dim (dim).
| Enter_insert_mode : string capEnter insert mode (smir).
| Enter_reverse_mode : string capTurn on reverse video (rev).
| Enter_standout_mode : string capBegin standout mode (smso).
| Enter_underline_mode : string capTurn on underline (smul).
| Exit_alt_charset : string capEnd alternate character set (rmacs).
| Exit_attribute_mode : string capTurn off all attributes (sgr0).
| Exit_insert_mode : string capEnd insert mode (rmir).
| Exit_standout_mode : string capEnd standout mode (rmso).
| Exit_underline_mode : string capEnd underline mode (rmul).
| Flash_screen : string capVisible bell (flash).
| Insert_character : string capInsert one character (ich1).
| Insert_line : string capInsert one line (il1).
| Keypad_local : string capLeave keypad transmit mode (rmkx).
| Keypad_xmit : string capEnter keypad transmit mode (smkx).
| Newline : string capNewline, behaves like carriage return followed by line feed (nel).
| Reset_1string : string capReset string 1 (rs1).
| Reset_2string : string capReset string 2 (rs2).
| Restore_cursor : string capRestore saved cursor position (rc).
| Save_cursor : string capSave cursor position (sc).
| Scroll_forward : string capScroll forward one line (ind).
| Scroll_reverse : string capScroll reverse one line (ri).
| Tab : string capTab character (ht).
| Column_address : (int -> string) capColumn_address: move cursor to column n (hpa).
| Cursor_position : ((int * int) -> string) capCursor_position: move cursor to (row, col) (cup). The terminfo %-expression applies coordinate transformations (e.g. %i for 1-based indexing).
| Delete_chars : (int -> string) capDelete_chars: delete n characters (dch).
| Delete_lines : (int -> string) capDelete_lines: delete n lines (dl).
| Insert_chars : (int -> string) capInsert_chars: insert n characters (ich).
| Insert_lines : (int -> string) capInsert_lines: insert n lines (il).
| Parm_down_cursor : (int -> string) capParm_down_cursor: move cursor down n lines (cud).
| Parm_left_cursor : (int -> string) capParm_left_cursor: move cursor left n characters (cub).
| Parm_right_cursor : (int -> string) capParm_right_cursor: move cursor right n characters (cuf).
| Parm_up_cursor : (int -> string) capParm_up_cursor: move cursor up n lines (cuu).
| Repeat_char : ((char * int) -> string) capRepeat_char: repeat character (c, n) times (rep).
| Row_address : (int -> string) capRow_address: move cursor to row n (vpa).
| Set_background : (int -> string) capSet_background: set background to color index n (setab).
| Set_foreground : (int -> string) capSet_foreground: set foreground to color index n (setaf).
The type for capability tokens.
The phantom type parameter encodes the OCaml type returned by get:
bool cap — boolean flags.int cap — numeric quantities.string cap — fixed escape sequences.(… -> string) cap — parameterized escape sequences. The returned function evaluates the terminfo %-expression and allocates a fresh string on each call.Each constructor maps to a standard terminfo capability whose short name appears in the constructor's documentation.
The type for terminfo entries. A value of this type is an immutable, in-memory handle to a parsed terminfo entry. It can be shared freely across threads.
load ?term () is the terminfo entry for terminal type term.
term defaults to the value of the TERM environment variable.
The search order is /usr/share/terminfo, /lib/terminfo, /etc/terminfo, and $HOME/.terminfo (when present). The entry is parsed eagerly; each call creates a fresh, independent handle.
Errors with `Not_found if no entry is found and `Parse_error msg if the file cannot be decoded.
Raises Sys_error if the entry exists but cannot be read.
get ti cap is the value of cap in ti, if declared.
For parameterized capabilities the returned function evaluates the terminfo %-expression and allocates a fresh string on each call. The function never mutates ti.
Note. Has_colors is synthesized from Max_colors and always yields Some true or Some false.