|
@@ -71,7 +71,7 @@ type style =
|
|
|
|
|
|
(* General function to print things *)
|
|
(* General function to print things *)
|
|
let print ~color ~style message =
|
|
let print ~color ~style message =
|
|
- (* Shorthand *)
|
|
|
|
|
|
+ (* Alias *)
|
|
let cpcolor = Color_print.color in
|
|
let cpcolor = Color_print.color in
|
|
match !Const.no_color with
|
|
match !Const.no_color with
|
|
| true -> printf "%s" message
|
|
| true -> printf "%s" message
|
|
@@ -89,11 +89,11 @@ let print ~color ~style message =
|
|
| Cyan -> cpcolor ~color:`Cyan message
|
|
| Cyan -> cpcolor ~color:`Cyan message
|
|
) |> (* Finaly print escaped string *)
|
|
) |> (* Finaly print escaped string *)
|
|
(fun colored_msg ->
|
|
(fun colored_msg ->
|
|
- let open Color_print in
|
|
|
|
- match style with
|
|
|
|
- | Bold -> bold_printf "%s" colored_msg
|
|
|
|
- | Underline -> underline_printf "%s" colored_msg
|
|
|
|
- | Normal -> printf "%s" colored_msg
|
|
|
|
|
|
+ let open Color_print in
|
|
|
|
+ match style with
|
|
|
|
+ | Bold -> bold_printf "%s" colored_msg
|
|
|
|
+ | Underline -> underline_printf "%s" colored_msg
|
|
|
|
+ | Normal -> printf "%s" colored_msg
|
|
)
|
|
)
|
|
end
|
|
end
|
|
;;
|
|
;;
|
|
@@ -102,40 +102,40 @@ let print ~color ~style message =
|
|
* The higher is the number, the more important the message is, the lower
|
|
* The higher is the number, the more important the message is, the lower
|
|
* verbosity value display it *)
|
|
* verbosity value display it *)
|
|
let check_verbosity ~f function_number =
|
|
let check_verbosity ~f function_number =
|
|
- match function_number <= !Const.verbosity with
|
|
|
|
|
|
+ match function_number <= !Const.verbosity with
|
|
true -> (* Display the message *)
|
|
true -> (* Display the message *)
|
|
- f ()
|
|
|
|
- | false -> ()
|
|
|
|
|
|
+ f ()
|
|
|
|
+ | false -> ()
|
|
;;
|
|
;;
|
|
|
|
|
|
|
|
|
|
(* Print debugging, information, important... messages *)
|
|
(* Print debugging, information, important... messages *)
|
|
let debug message =
|
|
let debug message =
|
|
- check_verbosity ~f:(fun () ->
|
|
|
|
- let mess = (Time.now() |> Time.to_string) ^ " " ^ message ^ "\n" in
|
|
|
|
- print ~color:Plum ~style:Underline mess
|
|
|
|
- ) 5
|
|
|
|
|
|
+ check_verbosity ~f:(fun () ->
|
|
|
|
+ let mess = (Time.now() |> Time.to_string) ^ " " ^ message ^ "\n" in
|
|
|
|
+ print ~color:Plum ~style:Underline mess
|
|
|
|
+ ) 5
|
|
;;
|
|
;;
|
|
|
|
|
|
let info message =
|
|
let info message =
|
|
- check_verbosity ~f:(fun () ->
|
|
|
|
- let mess = message ^ "\n" in
|
|
|
|
- print ~color:White ~style:Normal mess
|
|
|
|
- ) 3
|
|
|
|
|
|
+ check_verbosity ~f:(fun () ->
|
|
|
|
+ let mess = message ^ "\n" in
|
|
|
|
+ print ~color:White ~style:Normal mess
|
|
|
|
+ ) 3
|
|
;;
|
|
;;
|
|
|
|
|
|
let warning message =
|
|
let warning message =
|
|
- check_verbosity ~f:(fun () ->
|
|
|
|
- let mess = message ^ "\n" in
|
|
|
|
- print ~color:Red ~style:Bold mess
|
|
|
|
- ) 1
|
|
|
|
|
|
+ check_verbosity ~f:(fun () ->
|
|
|
|
+ let mess = message ^ "\n" in
|
|
|
|
+ print ~color:Red ~style:Bold mess
|
|
|
|
+ ) 1
|
|
;;
|
|
;;
|
|
|
|
|
|
(* Type for the answers *)
|
|
(* Type for the answers *)
|
|
type answer = Yes | No;;
|
|
type answer = Yes | No;;
|
|
(* Usefull to display result *)
|
|
(* Usefull to display result *)
|
|
let answer2str = function
|
|
let answer2str = function
|
|
- Yes -> "Yes" | No -> "No"
|
|
|
|
|
|
+ Yes -> "Yes" | No -> "No"
|
|
;;
|
|
;;
|
|
(* State of the program, if you should always answer yes, no or ask to the user
|
|
(* State of the program, if you should always answer yes, no or ask to the user
|
|
* (default)*)
|
|
* (default)*)
|
|
@@ -151,44 +151,44 @@ let check_assume_yes ~f =
|
|
|
|
|
|
(* Get confirmation
|
|
(* Get confirmation
|
|
* TODO:
|
|
* TODO:
|
|
- * allow option like -y
|
|
|
|
- * test it (display, line return, etc...) *)
|
|
|
|
|
|
+ * allow option like -y
|
|
|
|
+ * test it (display, line return, etc...) *)
|
|
let rec confirm info =
|
|
let rec confirm info =
|
|
check_assume_yes ~f:(fun () ->
|
|
check_assume_yes ~f:(fun () ->
|
|
- print ~color:Cyan ~style:Normal info;
|
|
|
|
- print ~color:Cyan ~style:Normal "\n(Yes/No): ";
|
|
|
|
- (* XXX Be sure to show the message *)
|
|
|
|
- Out_channel.(flush stdout);
|
|
|
|
- let str_answer = In_channel.(input_line ~fix_win_eol:true stdin) in
|
|
|
|
- str_answer |> (function
|
|
|
|
- | Some "Y" | Some "y" | Some "Yes" | Some "YES" | Some "yes" -> Yes
|
|
|
|
- | Some "N" | Some "n" | Some "No" | Some "NO" | Some "no" -> No
|
|
|
|
- | Some _ | None ->
|
|
|
|
- warning "Please enter 'yes' or 'no' or 'y' or 'n'.";
|
|
|
|
- confirm info)
|
|
|
|
- )
|
|
|
|
|
|
+ print ~color:Cyan ~style:Normal info;
|
|
|
|
+ print ~color:Cyan ~style:Normal "\n(Yes/No): ";
|
|
|
|
+ (* XXX Be sure to show the message *)
|
|
|
|
+ Out_channel.(flush stdout);
|
|
|
|
+ let str_answer = In_channel.(input_line ~fix_win_eol:true stdin) in
|
|
|
|
+ str_answer |> (function
|
|
|
|
+ | Some "Y" | Some "y" | Some "Yes" | Some "YES" | Some "yes" -> Yes
|
|
|
|
+ | Some "N" | Some "n" | Some "No" | Some "NO" | Some "no" -> No
|
|
|
|
+ | Some _ | None ->
|
|
|
|
+ warning "Please enter 'yes' or 'no' or 'y' or 'n'.";
|
|
|
|
+ confirm info)
|
|
|
|
+ )
|
|
;;
|
|
;;
|
|
|
|
|
|
let ok message =
|
|
let ok message =
|
|
- check_verbosity ~f:(fun () ->
|
|
|
|
- let mess = message ^ "\n" in
|
|
|
|
- print ~color:Green ~style:Bold mess
|
|
|
|
- ) 2
|
|
|
|
|
|
+ check_verbosity ~f:(fun () ->
|
|
|
|
+ let mess = message ^ "\n" in
|
|
|
|
+ print ~color:Green ~style:Bold mess
|
|
|
|
+ ) 2
|
|
;;
|
|
;;
|
|
|
|
|
|
let tips message =
|
|
let tips message =
|
|
- check_verbosity ~f:(fun () ->
|
|
|
|
- let mess = message ^ "\n" in
|
|
|
|
- print ~color:Yellow ~style:Normal mess
|
|
|
|
- ) 4
|
|
|
|
|
|
+ check_verbosity ~f:(fun () ->
|
|
|
|
+ let mess = message ^ "\n" in
|
|
|
|
+ print ~color:Yellow ~style:Normal mess
|
|
|
|
+ ) 4
|
|
;;
|
|
;;
|
|
|
|
|
|
|
|
|
|
(* Reset printing, to avoid color problem on some terminal (Konsole), the *)
|
|
(* Reset printing, to avoid color problem on some terminal (Konsole), the *)
|
|
let reset () =
|
|
let reset () =
|
|
let open Color_print in
|
|
let open Color_print in
|
|
- match !already with
|
|
|
|
- | true -> debug "Reseted colors";
|
|
|
|
- normal "" |> printf "%s\n"
|
|
|
|
- | false -> debug "Not resetted"; ()
|
|
|
|
|
|
+ match !already with
|
|
|
|
+ | true -> debug "Reseted colors";
|
|
|
|
+ normal "" |> printf "%s\n"
|
|
|
|
+ | false -> debug "Not resetted"; ()
|
|
;;
|
|
;;
|