test_couleurs.ml 1.7 KB
Newer Older
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
1
let tag_functions = Format.(pp_get_formatter_stag_functions std_formatter ())
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
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

let () = Format.set_tags true

type color =
  | Black
  | Red
  | Green
  | Yellow
  | Blue
  | Magenta
  | Cyan
  | White

let color_code = function
  | Black -> 30
  | Red -> 31
  | Green -> 32
  | Yellow -> 33
  | Blue -> 34
  | Magenta -> 35
  | Cyan -> 36
  | White -> 37

let open_color c = Printf.sprintf "\027[1;%im" (color_code c)

let close_color = "\027[0m"

POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
29
(*let () = Format.printf "Ceci est un %sessai%s pour voir la couleur\n%!" (open_color Red) close_color *)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

let new_print_open_tag t = 
  match t with
  | "sig" -> Format.printf "SIGNATURE ("
  | "lex" -> Format.printf "LEXICON ("
  | "tag" -> Format.printf "TAG ("
  | _ -> ()

let new_print_close_tag = function
  | "sig" -> Format.printf ")"
  | "lex" -> Format.printf ")"
  | "tag" -> Format.printf ")"
  | _ -> ()

let new_mark_open_tag t = 
  match t with
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
46 47 48 49
  | Format.String_tag "sig" -> open_color Green
  | Format.String_tag "lex" -> open_color Red
  | Format.String_tag "tag" -> open_color Blue
  | _ ->  ""
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
50 51 52

let new_mark_close_tag = function _ -> close_color

POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
53
let () = Format.(pp_set_formatter_stag_functions std_formatter
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
54 55 56
						{tag_functions with
						  (*print_open_tag=new_print_open_tag;
						  print_close_tag=new_print_close_tag; *)
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
57 58
						  mark_open_stag=new_mark_open_tag;
						  mark_close_stag=new_mark_close_tag})
POGODALLA Sylvain's avatar
POGODALLA Sylvain committed
59 60 61


let () = Format.fprintf Format.std_formatter "@[<v5>@[Voici@ un@ example@ avec :@]@,@[<2>Plusieurs@ @{<tag>tags@}@ pour@ bien@ illustrer@ le@ phénomène@ et@ vérifier@ que@ ça@ marche@ bien@ avec@ une@ phrase@ assez@ longue@ pour@ tenir@ sur@ plusieurs@ lignes@]@,@[une@ @{<sig>signature@}@ tout@ d'abord@]@,@[puis@ un@ @{<lex>lexique@}@ ensuite@]@.@?"