Browse Source

Adapt all messages to new system

Leo 10 years ago
parent
commit
96d0f845b1
6 changed files with 25 additions and 17 deletions
  1. 1 1
      src/command_def.ml
  2. 5 3
      src/edit_command.ml
  3. 11 6
      src/exec_cmd.ml
  4. 2 2
      src/file_com.ml
  5. 2 1
      src/remove_command.ml
  6. 4 4
      src/tmp_file.ml

+ 1 - 1
src/command_def.ml

@@ -84,7 +84,7 @@ let commands =
     args
 
     (fun rc_file_name reset_tmp list_commands add delete number modify num_cmd () ->
-        Messages.info "Parsed command line arguments";
+        Messages.debug "Parsed command line arguments";
        (* Use given rc file, should run the nth argument if present *)
        Const.rc_file := rc_file_name;
        (* Obtain data from rc_file *)

+ 5 - 3
src/edit_command.ml

@@ -76,7 +76,8 @@ let run ~(rc:File_com.t) position =
     Sys.command edit
     |> (function
         0 -> ()
-        | n -> printf "Error while running %s: error code %i" edit n);
+        | n -> sprintf "Error while running %s: error code %i" edit n
+        |> Messages.warning);
 
     (* Reading and applying the result *)
     let new_commands = In_channel.read_lines tmp_edit in
@@ -84,11 +85,12 @@ let run ~(rc:File_com.t) position =
     let updated_rc = { rc with Settings_t.progs = cmd_list} in
     File_com.write updated_rc;
     (* Display the result *)
-    printf "'%s' -> '%s'\n\n" original_command
+    sprintf "'%s' -> '%s'\n\n" original_command
         (List.fold
             ~f:(fun accum item -> String.concat [ accum ; item ; "\n" ])
             ~init:""
-            new_commands);
+            new_commands)
+        |> Messages.ok;
     let reread_rc = File_com.init_rc () in
     (* Display new rc file *)
     List_rc.run ~rc:reread_rc

+ 11 - 6
src/exec_cmd.ml

@@ -40,9 +40,10 @@ open Core.Std;;
  * XXX Maybe better in some lib *)
 (* TODO Allow to set it in configuration file *)
 let set_title new_title =
-    (* Use echo command *)
+    (* Use echo command to set term  title *)
     Sys.command (sprintf "echo -en \"\\033]0;%s\\a\"" new_title)
-    |> function | 0 -> () | _ -> printf "Error while setting terminal title"
+    |> function | 0 -> () | _ -> sprintf "Error while setting terminal title"
+    |> Messages.warning
 ;;
 
 (* Function to return the corresponding command to a number *)
@@ -54,8 +55,11 @@ let num_cmd_to_cmd ~cmd_list number =
        * an empty string after displaying error. *)
       | Some x -> set_title x; x
       (* TODO Make this printing configurable *)
-      | None -> printf "All has been launched!\n\
-      You can reset with '-r'\n"; ""
+      | None ->
+          Messages.ok "All has been launched!\n";
+          Messages.tips "You can reset with '-r'";
+          (* Return empty string *)
+          ""
 ;;
 
 (* Function to determinate what is the next command to
@@ -72,15 +76,16 @@ let display_result command status =
     match status with
     | 0 -> (* No problem, do nothing *) ()
     | _ -> (* Problem occur,  display it *)
-            printf "Problem while running: '%s'\nExited with code: %i\n"
+            sprintf "Problem while running: '%s'\nExited with code: %i\n"
             command status
+    |> Messages.warning
 ;;
 
 (* Execute some command and log it *)
 let execute ?(display=true) cmd =
     Tmp_file.log ~func:((+) 1) ();
     if display then
-        print_endline cmd;
+        Messages.ok cmd;
     (* We can remove lock file since number in tmp_file has been incremented *)
     Lock.remove ();
     Sys.command cmd

+ 2 - 2
src/file_com.ml

@@ -60,8 +60,8 @@ let rc_template () =
  * exist *)
 let create_rc_file ~name =
   (* Notify that we initialise config file *)
-  printf "Initializing empty configuration file in %s\n\
-  \nFeedback is welcomed at leowzukw@vmail.me\n\n" name;
+  sprintf "Initializing empty configuration file in %s\n" name |> Messages.warning;
+  Messages.tips "Feedback is welcomed at leowzukw@vmail.me\n";
   let compact_rc_file = Settings_j.string_of_rc_file (rc_template () ()) in
   let readable_rc_file = Yojson.Basic.prettify compact_rc_file in (* Create human readable string for rc file *)
   let out_file = Out_channel.create name in

+ 2 - 1
src/remove_command.ml

@@ -68,7 +68,8 @@ let run ~(rc:File_com.t) n_to_remove =
         ~default:((List.length actual_list) - 1) in
     (* Remove the nth command, after display it *)
     let removed,new_list = remove actual_list nth in
-    printf "Removing: %s\n\n" removed;
+    sprintf "Removing: %s\n" removed
+    |> Messages.warning;
     (* Write new list to rc file *)
     let updated_rc = { rc with Settings_t.progs = new_list } in
     File_com.write updated_rc;

+ 4 - 4
src/tmp_file.ml

@@ -62,7 +62,7 @@ let rec read () =
     with _ ->
         (* If file is not in the right format, delete it and create a new one.
          * Then, read it *)
-        printf "Reinitialises tmp file\n"; (* TODO Make it settable *)
+        Messages.ok "Reinitialises tmp file\n"; (* TODO Make it settable *)
         Sys.remove name;
         create_tmp_file ();
         read ()
@@ -119,10 +119,10 @@ let log ?(func= (+) 1 ) () =
     * else display an error message *)
 let reset cmd_num =
     match cmd_num with
-    | 0 -> Sys.remove Const.tmp_file; printf "Tmp file removed\n"
+    | 0 -> Sys.remove Const.tmp_file; Messages.ok "Tmp file removed"
     | n when n > 0 ->
             (* Set the number *)
             log ~func:((fun a b -> a) n) ();
-            printf "Tmp file reseted to %i\n" n
-    | _ -> printf "Invalid number\n" (* TODO Make it settable *)
+            sprintf "Tmp file reseted to %i" n |> Messages.ok
+    | _ -> Messages.warning "Invalid number" (* TODO Make it settable *)
 ;;