Browse Source

Finish to implement color parsing

 + Code taken from 2d730795f668c34adc9e373aa5c109a224c6520d
 + Update some function name for the internal Color_print (for instance
 boldprint -> bold_print)
 + Need reindentation
Leo 9 years ago
parent
commit
f1b6de1da7
1 changed files with 29 additions and 2 deletions
  1. 29 2
      src/messages.ml

+ 29 - 2
src/messages.ml

@@ -71,7 +71,31 @@ type style =
 
 (* General function to print things *)
 let print ~color ~style message =
-  failwith "Not implemented"
+  (* Shorthand *)
+  let cpcolor = Color_print.color in
+    match !Const.no_color with
+    | true -> printf "%s" message
+    | false -> begin (* Use colors *)
+        (* Log that we used colored messages *)
+        log_already ();
+        (* This code create proper escapement to display text with bold/color... *)
+        color |>
+        (function
+          | Green -> cpcolor ~color:`Green message
+          | Red -> cpcolor ~color:`Red message
+          | Yellow -> cpcolor ~color:`Yellow message
+          | White -> cpcolor ~color:`White message
+          | Plum -> cpcolor ~color:`Plum message
+          | Cyan -> cpcolor ~color:`Cyan message
+        ) |> (* Finaly print escaped string *)
+        (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
+        )
+      end
 ;;
 
 (* Behave in a conform way to verbosity
@@ -163,5 +187,8 @@ let tips message =
 (* Reset printing, to avoid color problem on some terminal (Konsole), the  *)
 let reset () =
   let open Color_print in
-  failwith "Not implemented"
+  match !already with
+  | true -> debug "Reseted colors";
+    normal "" |> printf "%s\n"
+  | false -> debug "Not resetted"; ()
 ;;