]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/rt_transition/hls.ml
9c12ae1c74ec42be84a07d4fa057dcd4ec35a6b5
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / rt_transition / hls.ml
1 let cols = int_of_string (Sys.getenv "COLUMNS")
2
3 let hl = ref []
4
5 let normal = "\x1B[0m"
6
7 let color = "\x1B[32m"
8
9 let add s =
10    if s = "" then false else
11    begin hl := s :: !hl; true end
12
13 let rec read ich =
14    if Scanf.fscanf ich "%s " add then read ich
15
16 let length l s = max l (String.length s)
17
18 let write l c s =
19    let pre, post = if List.mem s !hl then color, normal else "", "" in
20    let spc = String.make (l - String.length s) ' ' in
21    let bol, ret =
22        if c = 0 || c = cols then "", l else
23        if c + l < cols then " ", c + succ l else "\n", l
24    in
25    Printf.printf "%s%s%s%s%s" bol pre s post spc;
26    ret
27
28 let process fname =
29    let ich = open_in fname in
30    read ich; close_in ich
31
32 let help = ""
33
34 let main =
35    Arg.parse [] process help;
36    let files = Sys.readdir "." in
37    Array.fast_sort String.compare files;
38    let l = Array.fold_left length 0 files in
39    if cols < l then failwith "window too small";
40    let c = Array.fold_left (write l) 0 files in
41    if 0 < c && c < cols then print_newline ()