Browse Source

Add reediting to edit command

Leo 9 years ago
parent
commit
4870e110f2
5 changed files with 27 additions and 13 deletions
  1. 2 1
      CHANGELOG.md
  2. 2 3
      dev.json
  3. 20 7
      src/edit_command.ml
  4. 1 1
      src/messages.ml
  5. 2 1
      src/tmp_file.ml

+ 2 - 1
CHANGELOG.md

@@ -14,7 +14,8 @@
    command or the next one. The problem is that you can't call it with an
    command or the next one. The problem is that you can't call it with an
    option. To do this, use the `run` subcommand.
    option. To do this, use the `run` subcommand.
  + Improve list subcommand, now using Textutils library, displaying in an array
  + Improve list subcommand, now using Textutils library, displaying in an array
- + Improve editing command (explain how to use to add commands, improve messages…)
+ + Improve editing command (explain how to use to add commands, improve
+   messages, offer to reedit when nothing was done).
  + Code clean up
  + Code clean up
  + Add unit tests
  + Add unit tests
  + Add licence warning
  + Add licence warning

+ 2 - 3
dev.json

@@ -1,8 +1,7 @@
 {
 {
   "progs": [
   "progs": [
-    "ydump dev.json", "task", "task +next", "task +rdv +me",
+    "ydump dev.json", "task", "task +next", "task +rdv", "echo \"Finish\"",
-    "echo \"Finish\"", "bdump -w daemon,rc,commands /tmp/v033",
+    "bdump -w daemon,rc,commands /tmp/v033", "ydump dev.json"
-    "ydump dev.json"
   ],
   ],
   "settings": []
   "settings": []
 }
 }

+ 20 - 7
src/edit_command.ml

@@ -74,7 +74,7 @@ let rec gen_modification items =
 
 
 (* Function which get the nth element, put it in a file, let the user edit it,
 (* Function which get the nth element, put it in a file, let the user edit it,
  * and then remplace with the new result *)
  * and then remplace with the new result *)
-let run ~(rc:File_com.t) position =
+let rec run ~(rc:File_com.t) position =
     (* Current list of commands *)
     (* Current list of commands *)
     let current_list = rc.Settings_t.progs in
     let current_list = rc.Settings_t.progs in
 
 
@@ -108,11 +108,24 @@ let run ~(rc:File_com.t) position =
     File_com.write updated_rc;
     File_com.write updated_rc;
     (* Display the result, only if modified *)
     (* Display the result, only if modified *)
     let new_cmd_mod = gen_modification new_commands in
     let new_cmd_mod = gen_modification new_commands in
-    if ( original_command <> new_cmd_mod )
+    (* We are doing things in this order to avoid multiple listing of rc file
-    then sprintf "'%s' -> '%s'\n" original_command new_cmd_mod |> Messages.ok
+     * when reediting. *)
-    else Messages.warning "Nothing changed";
+    if ( original_command = new_cmd_mod )
+    then (* Nothing change, try reediting *)
+      begin
+        let open Messages in
+        warning "Nothing changed.";
+        confirm "Do you want to reedit?"
+        |> function
+          | Yes -> run ~rc position
+          | No -> ()
+      end
 
 
-    let reread_rc = File_com.init_rc () in
+    else (* Display summary of changes *)
-    (* Display new rc file *)
+      begin
-    List_rc.run ~rc:reread_rc ()
+        sprintf "'%s' -> '%s'\n" original_command new_cmd_mod |> Messages.ok;
+        (* Display new rc file *)
+        let reread_rc = File_com.init_rc () in
+        List_rc.run ~rc:reread_rc ()
+      end;
 ;;
 ;;

+ 1 - 1
src/messages.ml

@@ -154,7 +154,7 @@ let check_assume_yes ~f =
 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 info;
-    print ~color:Cyan ~style:Normal "\nAre you sure ? (Yes/No): ";
+    print ~color:Cyan ~style:Normal "\n(Yes/No): ";
     (* XXX Be sure to show the message *)
     (* XXX Be sure to show the message *)
     Out_channel.(flush stdout);
     Out_channel.(flush stdout);
     let str_answer = In_channel.(input_line ~fix_win_eol:true stdin) in
     let str_answer = In_channel.(input_line ~fix_win_eol:true stdin) in

+ 2 - 1
src/tmp_file.ml

@@ -222,7 +222,8 @@ let reset_all () =
     write Tmp_biniou_t.{ tmp with rc = List.Assoc.add tmp.rc name [] }
     write Tmp_biniou_t.{ tmp with rc = List.Assoc.add tmp.rc name [] }
   in
   in
   Messages.debug "Asking question";
   Messages.debug "Asking question";
-  Messages.confirm "You will lose number of launch for every command."
+  Messages.confirm "You will lose number of launch for every command.\
+    Are you sure?"
   |> (fun answer -> sprintf "Answer %s" (Messages.answer2str answer) |> Messages.debug; answer) (* Spy *)
   |> (fun answer -> sprintf "Answer %s" (Messages.answer2str answer) |> Messages.debug; answer) (* Spy *)
     |> function
     |> function
       Messages.Yes -> reset_without_ask ()
       Messages.Yes -> reset_without_ask ()