compat, reformat

This commit is contained in:
Simon Cruanes 2023-04-07 11:05:52 -04:00
parent c2952e0ce6
commit 74e3a9e875
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 45 additions and 79 deletions

View file

@ -343,7 +343,6 @@ let int x : t = text (string_of_int x)
let float x : t = text (string_of_float x)
let float_hex x : t = textpf "%h" x
let text_quoted s : t = text (Printf.sprintf "%S" s)
let text_zero_width s : t = { view = Text_zero_width s; wfl = 0 }
let append_l ?(sep = nil) l =
@ -393,9 +392,7 @@ let of_seq ?(sep = nil) f seq : t =
loop true seq
let bracket l d r : t = group (text l ^ nest (String.length l) d ^ text r)
let bracket2 l d r : t = group (text l ^ nest 2 (nl ^ d) ^ nl ^ text r)
let sexp_l l : t = char '(' ^ nest 1 (group (append_nl l ^ char ')'))
let sexp_apply a l : t = sexp_l (text a :: l)
@ -407,25 +404,15 @@ end
module Term_color = struct
type color =
[ `Black
| `Red
| `Yellow
| `Green
| `Blue
| `Magenta
| `Cyan
| `White
]
[ `Black | `Red | `Yellow | `Green | `Blue | `Magenta | `Cyan | `White ]
type style =
[ `FG of color (* foreground *)
| `BG of color (* background *)
| `Bold
| `Reset
| `Underline
]
| `Underline ]
open struct
let int_of_color_ = function
| `Black -> 0
| `Red -> 1
@ -444,9 +431,7 @@ module Term_color = struct
| `Underline -> 4
let spf = Printf.sprintf
let string_of_style a = spf "\x1b[%dm" (code_of_style a)
let reset = string_of_style `Reset
let string_of_style_list = function
@ -454,13 +439,10 @@ module Term_color = struct
| [ a ] -> string_of_style a
| [ a; b ] -> spf "\x1b[%d;%dm" (code_of_style a) (code_of_style b)
| [ a; b; c ] ->
spf "\x1b[%d;%d;%dm" (code_of_style a) (code_of_style b)
(code_of_style c)
spf "\x1b[%d;%d;%dm" (code_of_style a) (code_of_style b) (code_of_style c)
| l ->
let buf = Buffer.create 32 in
let pp_num c =
Buffer.add_string buf (string_of_int (code_of_style c))
in
let pp_num c = Buffer.add_string buf (string_of_int (code_of_style c)) in
Buffer.add_string buf "\x1b[";
List.iteri
(fun i c ->
@ -476,7 +458,6 @@ module Term_color = struct
pre = (fun out l -> Out.string out (string_of_style_list l));
post = (fun out _l -> Out.string out reset);
}
end
(** Set the foreground color. *)
let color (c : color) (d : t) : t = ext ext_style_ [ `FG c ] d

View file

@ -244,25 +244,10 @@ end
(** Simple colors in terminals *)
module Term_color : sig
type color =
[ `Black
| `Blue
| `Cyan
| `Green
| `Magenta
| `Red
| `White
| `Yellow
]
[ `Black | `Blue | `Cyan | `Green | `Magenta | `Red | `White | `Yellow ]
type style =
[ `BG of color
| `Bold
| `FG of color
| `Reset
| `Underline
]
type style = [ `BG of color | `Bold | `FG of color | `Reset | `Underline ]
val color : color -> t -> t
val style_l : style list -> t -> t
end