Skip to content

Commit 31ac8b5

Browse files
committed
improve lm_terminfo
1 parent c82ba68 commit 31ac8b5

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

cutil/lm_terminfo.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ static int load_terminfo() {
4343

4444
}
4545

46+
/* Converts termcap data type to capname */
47+
static char *capname(int i) {
48+
49+
char *names[] = {"bold", "snrmq", "ssubm", "ssupm", "smul", "sitm", "sgr0"};
50+
51+
return names[i];
52+
}
53+
4654
#endif /* NCURSES support? */
4755

4856
/*
@@ -69,7 +77,8 @@ value caml_tgetstr(value id) {
6977
in. */
7078
#ifdef NCURSES
7179
if(load_terminfo() == 0) {
72-
termdata = tigetstr(String_val(id));
80+
char *name = capname(Int_val(id));
81+
termdata = tigetstr(name);
7382
}
7483
#endif /* NCURSES */
7584

util/lm_terminfo.ml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
* LICENSE.libmojave for more details.
2323
*)
2424

25+
(* Terminal Capname *)
26+
type termcap = Bold | Normal | Subscript | Superscript
27+
| Underline | Italics | Reset
2528

26-
(* The C function takes a string ID, and returns the escape sequence
29+
(* The C function takes a integer, and returns the escape sequence
2730
(or an empty string if the ID is not defined for this terminal). *)
2831
external caml_tgetstr_enabled : unit -> bool = "caml_tgetstr_enabled"
29-
external caml_tgetstr : string -> string = "caml_tgetstr"
32+
external caml_tgetstr : termcap -> string = "caml_tgetstr"
3033

3134

3235
(* Tgetstr is enabled only if the terminal is defined *)
@@ -48,8 +51,18 @@ let tgetstr id =
4851

4952

5053
(* Various terminfo identifier names for use with tgetstr *)
51-
let enter_bold_mode = "bold"
52-
let exit_attribute_mode = "sgr0"
54+
let enter_bold_mode = Bold
55+
56+
let enter_normal_quality = Normal
57+
58+
let enter_subscript_mode = Subscript
59+
let enter_superscript_mode = Superscript
60+
61+
let enter_underline_mode = Underline
62+
63+
let enter_italics_mode = Italics
64+
65+
let exit_attribute_mode = Reset
5366

5467

5568
(* xterm_ok ()

util/lm_terminfo.mli

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@
2222
* LICENSE.libmojave for more details.
2323
*)
2424

25+
type termcap
2526

2627
(* tgetstr id
2728
Lookup the terminal capability with indicated id. This assumes the
2829
terminfo to lookup is given in the TERM environment variable. This
2930
function returns None if the terminal capability is not defined. *)
30-
val tgetstr : string -> string option
31-
31+
val tgetstr : termcap -> string option
3232

3333
(* Various terminfo identifier names for use with tgetstr *)
34-
val enter_bold_mode : string
35-
val exit_attribute_mode : string
36-
34+
val enter_bold_mode : termcap
35+
val enter_italics_mode : termcap
36+
val enter_normal_quality : termcap
37+
val enter_subscript_mode : termcap
38+
val enter_superscript_mode : termcap
39+
val enter_underline_mode : termcap
40+
val exit_attribute_mode : termcap
3741

3842
(* xterm_escape_begin ()
3943
Display XTerm title begin escape, if available. *)

0 commit comments

Comments
 (0)