package codept-lib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file format_tags.ml

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#0 "format_tags.mlp"
type t
= Format.stag
#2 "format_tags.mlp"
= ..
#4 "format_tags.mlp"

type t +=
  | Info | Notification | Warning | Error | Critical
  | Em | Loc | Title | M

let of_string =
  function
  | "info" | "0" -> Info
  | "notification" | "1" -> Notification
  | "warning" | "2" -> Warning
  | "error" | "3" -> Error
  | "critical" | "4" -> Critical
  | "em" -> Em
  | "loc" -> Loc
  | "title" -> Title
  | "m" -> M
  | _ -> Info

let to_string = function
  | Info -> "info"
  | Notification -> "notification"
  | Warning -> "warning"
  | Error -> "error"
  | Critical -> "critical"
  | Em -> "em"
  | Loc -> "loc"
  | Title -> "title"
  | M -> "m"
  | _ -> "?"


let parse x =
#38 "format_tags.mlp"
  x
#40 "format_tags.mlp"

let serialize x =
#44 "format_tags.mlp"
  x
#46 "format_tags.mlp"

let mark_open_tag tag =
  let b = "\x1b[1m" in
  match parse tag with
  | Critical -> b ^ "\x1b[91m"
  | Error -> b ^ "\x1b[31m"
  | Warning -> b ^ "\x1b[35m"
  | Notification -> b ^ "\x1b[36m"
  | Info -> b
  | Em -> b (* "\x1b[3m" *)
  | Loc -> b
  | Title -> b
  | M -> b
  | _ -> b

let mark_close_tag _tag =
  "\x1b[0m"

let enable ~simple ppf =
  if simple then begin
    Format.pp_set_tags ppf false;
    Format.pp_set_mark_tags ppf false;
  end else begin
  Format.pp_set_tags ppf true;
  Format.pp_set_mark_tags ppf true;
#73 "format_tags.mlp"
  Format.pp_set_formatter_stag_functions ppf
#77 "format_tags.mlp"
    { (Format.pp_get_formatter_stag_functions ppf ()) with
      mark_open_stag=mark_open_tag;
      mark_close_stag=mark_close_tag
    }
  end
#83 "format_tags.mlp"

let with_tag tag printer ppf x =
#87 "format_tags.mlp"
  Format.pp_open_stag ppf (serialize tag);
#91 "format_tags.mlp"
  printer ppf x;
  Format.pp_close_stag ppf ()

#95 "format_tags.mlp"
let tagged tag ppf x =
  with_tag tag Format.pp_print_string ppf x