Browse Source

Try to fix #4

Leo 10 years ago
parent
commit
bf25b3fb86
3 changed files with 28 additions and 1 deletions
  1. 22 0
      src/messages.ml
  2. 2 0
      src/messages.mli
  3. 4 1
      src/oclaunch.ml

+ 22 - 0
src/messages.ml

@@ -41,6 +41,17 @@ open Core.Std;;
 (* TODO
     * allow to display bold & underlined messages *)
 
+(* Store whether a message was already displayed to reset if necessary (see
+ * function reset) *)
+let already = ref false
+
+(* Function to keep a trace of colored messages *)
+let log_already () =
+    match !already with
+    | false -> already := true
+    | true -> ()
+;;
+
 (* Types corresponding to some colors & style of the Core_extended.Color_print
  * library *)
 type color =
@@ -63,6 +74,8 @@ let print ~color ~style message =
     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
@@ -126,3 +139,12 @@ let tips message =
     print ~color:Yellow ~style:Normal mess
     ) 3
 ;;
+
+
+(* Reset printing, to avoid color problem on some terminal (Konsole), the  *)
+let reset () =
+    match !already with
+    | true -> debug "Resetted";
+        Core_extended.Color_print.normal "" |> printf "%s\n"
+    | false -> debug "Not resetted"; ()
+;;

+ 2 - 0
src/messages.mli

@@ -39,3 +39,5 @@ val info : string -> unit
 val warning : string -> unit
 val ok : string -> unit
 val tips : string -> unit
+
+val reset : unit -> unit

+ 4 - 1
src/oclaunch.ml

@@ -46,5 +46,8 @@ let version_number = "0.2.2-dev";;
 let build_info = ( "Build with OCaml version " ^ (Sys.ocaml_version) ^ " on " ^ (Sys.os_type) );;
 
 let () =
-  Command.run ~version:version_number ~build_info:build_info Command_def.commands
+  Command.run ~version:version_number ~build_info:build_info
+  Command_def.commands;
+  (* Reset display *)
+  Messages.reset ()
 ;;