-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp.ml
56 lines (43 loc) · 1.31 KB
/
pp.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
(* LIST OPERATIONS *)
let rec remove_before note lgamme =
match lgamme with
| [] -> raise Not_found
| (n,_) :: _ when n = note -> lgamme
| _ :: l' -> remove_before note l'
let rec prefix n l =
if n <= 0 then []
else match l with
| [] -> assert false
| e::l' -> e::prefix (n-1) l'
let rec last l =
match l with
| [] -> assert false
| e::[] -> e
| _::l' -> last l'
(* PRINTING *)
(*T.Black; T.Red; T.Green; T.Yellow; T.Blue; T.Magenta; T.Cyan; T.White; T.Default *)
module T = ANSITerminal
let color_to_string = function
| T.Black -> "black"
| T.Red -> "red"
| T.Green -> "green"
| T.Yellow -> "yellow"
| T.Blue -> "blue"
| T.Magenta -> "magent"
| T.Cyan -> "cyan"
| T.White -> "white"
| T.Default -> "def"
let str style s: string = T.sprintf style "%s" s;;
let rec print_list sep print fmt =
function
| [] -> ()
| [x] -> Format.fprintf fmt "%a" print x
| x :: r -> Format.fprintf fmt "%a%a%a" print x sep () (print_list sep print) r
let comma fmt () = Format.fprintf fmt ",@ "
let dot fmt () = Format.fprintf fmt "."
let semi fmt () = Format.fprintf fmt ";@ "
let newline fmt () = Format.fprintf fmt "@\n"
let brk fmt () = Format.fprintf fmt "@;"
let cut fmt () = Format.fprintf fmt "@,"
let nothing _fmt () = ()
let some_space fmt () = Format.fprintf fmt " @ "