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
type user_supplied =
{ ppf : Format.formatter option
; hide_cursor : bool option
; persistent : bool option
; max_width : int option option
; min_interval : Duration.t option option
}
module Default = struct
let ppf =
let ppf = Format.formatter_of_out_channel stderr in
Fmt.set_style_renderer ppf `Ansi_tty;
Fmt.set_utf_8 ppf true;
ppf
let hide_cursor = true
let persistent = true
let max_width = None
let min_interval = Some (Duration.of_sec (1. /. 60.))
end
let v ?ppf ?hide_cursor ?persistent ?max_width ?min_interval () =
{ ppf; hide_cursor; persistent; max_width; min_interval }
let merge_on ~f a b = match (f a, f b) with Some a, _ -> Some a | None, b -> b
let ( || ) a b =
{ ppf = merge_on a b ~f:(fun x -> x.ppf)
; hide_cursor = merge_on a b ~f:(fun x -> x.hide_cursor)
; persistent = merge_on a b ~f:(fun x -> x.persistent)
; max_width = merge_on a b ~f:(fun x -> x.max_width)
; min_interval = merge_on a b ~f:(fun x -> x.min_interval)
}
type t =
{ ppf : Format.formatter
; hide_cursor : bool
; persistent : bool
; max_width : int option
; min_interval : Duration.t option
}
let apply_defaults : user_supplied -> t =
fun { ppf; hide_cursor; persistent; max_width; min_interval } ->
{ ppf = Option.value ppf ~default:Default.ppf
; hide_cursor = Option.value hide_cursor ~default:Default.hide_cursor
; persistent = Option.value persistent ~default:Default.persistent
; max_width = Option.value max_width ~default:Default.max_width
; min_interval = Option.value min_interval ~default:Default.min_interval
}