2 * Simple terminfo interface.
3 * Copyright (C) 2002 Justin David Smith, Caltech
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation,
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Additional permission is given to link this library with the
20 * OpenSSL project's "OpenSSL" library, and with the OCaml runtime,
21 * and you may distribute the linked executables. See the file
22 * LICENSE.libmojave for more details.
26 (* The C function takes a string ID, and returns the escape sequence
27 (or an empty string if the ID is not defined for this terminal). *)
28 external caml_tgetstr_enabled
: unit -> bool = "caml_tgetstr_enabled"
29 external caml_tgetstr
: string -> string = "caml_tgetstr"
32 (* Tgetstr is enabled only if the terminal is defined *)
33 let tgetstr_enabled = caml_tgetstr_enabled
()
36 Lookup the terminal capability with indicated id. This assumes the
37 terminfo to lookup is given in the TERM environment variable. This
38 function returns None if the terminal capability is not defined. *)
40 if tgetstr_enabled then
41 let result = caml_tgetstr id
in
50 (* Various terminfo identifier names for use with tgetstr *)
51 let enter_bold_mode = "bold"
52 let exit_attribute_mode = "sgr0"
56 Check for an XTerm-compatible terminal, for the XTerm escapes. *)
58 (* XXX: strictly speaking, we should be using the "tsl"/"fsl" capabilities here, but those are often missing *)
61 match Sys.getenv
"TERM" with
62 "xterm" | "color_xterm" | "xterm-color" | "konsole" | "rxvt" ->
71 (* xterm_escape_begin ()
72 Display XTerm title begin escape, if available. *)
73 let xterm_escape_begin () =
80 (* xterm_escape_begin ()
81 Display XTerm title end escape, if available. *)
82 let xterm_escape_end () =