aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/terminal.mli
blob: e0fd7f2284cddf8d38c2b3058ff1bc44fdb24197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, *   INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2016     *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

type color = [
  `DEFAULT
| `BLACK
| `RED
| `GREEN
| `YELLOW
| `BLUE
| `MAGENTA
| `CYAN
| `WHITE
| `LIGHT_BLACK
| `LIGHT_RED
| `LIGHT_GREEN
| `LIGHT_YELLOW
| `LIGHT_BLUE
| `LIGHT_MAGENTA
| `LIGHT_CYAN
| `LIGHT_WHITE
| `INDEX of int
| `RGB of (int * int * int)
]

type style = {
  fg_color : color option;
  bg_color : color option;
  bold : bool option;
  italic : bool option;
  underline : bool option;
  negative : bool option;
}

val make : ?fg_color:color -> ?bg_color:color ->
  ?bold:bool -> ?italic:bool -> ?underline:bool ->
  ?negative:bool -> ?style:style -> unit -> style
(** Create a style from the given flags. It is derived from the optional
    [style] argument if given. *)

val merge : style -> style -> style
(** [merge s1 s2] returns [s1] with all defined values of [s2] overwritten. *)

val repr : style -> int list
(** Generate the ANSI code representing the given style. *)

val eval : style -> string
(** Generate an escape sequence from a style. *)

val reset : string
(** This escape sequence resets all attributes. *)

val has_style : Unix.file_descr -> bool
(** Whether an output file descriptor handles styles. Very heuristic, only
    checks it is a terminal. *)

val parse : string -> (string * style) list
(** Parse strings describing terminal styles in the LS_COLORS syntax. For
    robustness, ignore meaningless entries and drops undefined styles. *)