mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-01-27 03:14:49 -05:00
CCFormat: fix support of unrecognized styles
This commit is contained in:
parent
3ab9cd58e1
commit
24592bf926
1 changed files with 16 additions and 13 deletions
|
|
@ -238,6 +238,8 @@ let ansi_l_to_str_ = function
|
||||||
Buffer.add_string buf "m";
|
Buffer.add_string buf "m";
|
||||||
Buffer.contents buf
|
Buffer.contents buf
|
||||||
|
|
||||||
|
exception No_such_style
|
||||||
|
|
||||||
(* parse a tag *)
|
(* parse a tag *)
|
||||||
let style_of_tag_ s = match String.trim s with
|
let style_of_tag_ s = match String.trim s with
|
||||||
| "reset" -> [`Reset]
|
| "reset" -> [`Reset]
|
||||||
|
|
@ -258,7 +260,7 @@ let style_of_tag_ s = match String.trim s with
|
||||||
| "Magenta" -> [`FG `Magenta; `Bold]
|
| "Magenta" -> [`FG `Magenta; `Bold]
|
||||||
| "Cyan" -> [`FG `Cyan; `Bold]
|
| "Cyan" -> [`FG `Cyan; `Bold]
|
||||||
| "White" -> [`FG `White; `Bold]
|
| "White" -> [`FG `White; `Bold]
|
||||||
| s -> failwith ("unknown style: " ^ s)
|
| _ -> raise No_such_style
|
||||||
|
|
||||||
let color_enabled = ref false
|
let color_enabled = ref false
|
||||||
|
|
||||||
|
|
@ -268,20 +270,21 @@ let mark_open_tag st ~or_else s =
|
||||||
let style = style_of_tag_ s in
|
let style = style_of_tag_ s in
|
||||||
Stack.push style st;
|
Stack.push style st;
|
||||||
if !color_enabled then ansi_l_to_str_ style else ""
|
if !color_enabled then ansi_l_to_str_ style else ""
|
||||||
with Not_found -> or_else s
|
with No_such_style -> or_else s
|
||||||
|
|
||||||
let mark_close_tag st ~or_else s =
|
let mark_close_tag st ~or_else s =
|
||||||
try
|
(* check if it's indeed about color *)
|
||||||
let _ = style_of_tag_ s in (* check if it's indeed about color *)
|
match style_of_tag_ s with
|
||||||
let style =
|
| _ ->
|
||||||
try
|
let style =
|
||||||
ignore (Stack.pop st); (* pop current style (if well-scoped...) *)
|
try
|
||||||
Stack.top st (* look at previous style *)
|
ignore (Stack.pop st); (* pop current style (if well-scoped...) *)
|
||||||
with Stack.Empty ->
|
Stack.top st (* look at previous style *)
|
||||||
[`Reset]
|
with Stack.Empty ->
|
||||||
in
|
[`Reset]
|
||||||
if !color_enabled then ansi_l_to_str_ style else ""
|
in
|
||||||
with Not_found -> or_else s
|
if !color_enabled then ansi_l_to_str_ style else ""
|
||||||
|
| exception No_such_style -> or_else s
|
||||||
|
|
||||||
(* add color handling to formatter [ppf] *)
|
(* add color handling to formatter [ppf] *)
|
||||||
let set_color_tag_handling ppf =
|
let set_color_tag_handling ppf =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue