Browse Source

Update list subcommand to new tmp file format

 + Make some other command working: add, edit, remove
 + A few command don't work, esp. state
 + Quite quick implementation in listrc.ml, see FIXME, TODO and XXX
 + Update CHANGELOG
Leo 9 years ago
parent
commit
42e132e79d
8 changed files with 36 additions and 22 deletions
  1. 1 0
      CHANGELOG.md
  2. 3 2
      dev.json
  3. 1 1
      src/add_command.ml
  4. 1 1
      src/command_def.ml
  5. 1 1
      src/default.ml
  6. 1 1
      src/edit_command.ml
  7. 27 15
      src/list_rc.ml
  8. 1 1
      src/remove_command.ml

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@
    without any argument. This way, the program tries to launch the corresponding
    without any argument. This way, the program tries to launch the corresponding
    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
  + Code clean up
  + Code clean up
  + Add unit tests
  + Add unit tests
  + Add licence warning
  + Add licence warning

+ 3 - 2
dev.json

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

+ 1 - 1
src/add_command.ml

@@ -63,6 +63,6 @@ let run ~(rc:File_com.t) position =
     File_com.write updated_rc;
     File_com.write updated_rc;
     (* Display the result *)
     (* Display the result *)
     let reread_rc = File_com.init_rc () in
     let reread_rc = File_com.init_rc () in
-    List_rc.run ~rc:reread_rc
+    List_rc.run ~rc:reread_rc ()
 ;;
 ;;
 
 

+ 1 - 1
src/command_def.ml

@@ -132,7 +132,7 @@ let list =
       +> shared_params
       +> shared_params
     )
     )
     (fun { rc } () ->
     (fun { rc } () ->
-      List_rc.run ~rc)
+      List_rc.run ~rc ())
 ;;
 ;;
 
 
 (* To add a command to rc file, from stdin or directly *)
 (* To add a command to rc file, from stdin or directly *)

+ 1 - 1
src/default.ml

@@ -36,7 +36,7 @@
 
 
 open Core.Std;;
 open Core.Std;;
 
 
-(* The module containing the step runned when the program is
+(* The module containing the step run when the program is
  * used without argument *)
  * used without argument *)
 
 
 (* cmd_number is the number of the command the user wants
 (* cmd_number is the number of the command the user wants

+ 1 - 1
src/edit_command.ml

@@ -111,5 +111,5 @@ let run ~(rc:File_com.t) position =
         |> Messages.ok;
         |> Messages.ok;
     let reread_rc = File_com.init_rc () in
     let reread_rc = File_com.init_rc () in
     (* Display new rc file *)
     (* Display new rc file *)
-    List_rc.run ~rc:reread_rc
+    List_rc.run ~rc:reread_rc ()
 ;;
 ;;

+ 27 - 15
src/list_rc.ml

@@ -38,20 +38,32 @@ open Core.Std;;
 
 
 (* This modules contains function to list the content of the rc file *)
 (* This modules contains function to list the content of the rc file *)
 
 
-(* Display the command with its number, with a '*' and different color if it is the current one *)
+(* Function which list, rc would be automatically reread, this optional
-let disp_cmd_num current_number number command =
+ * argument is kept for backward compatibility *)
-    (* If number is the global current one print a '*' *)
+(* FIXME Remove ?rc or use it *)
-    let prepend = (if current_number = number then "* " else "  ") in
+(* TODO:
-    sprintf "%s%i: %s" prepend number command
+  * Test it, esp. ordering
-    |> (fun concatenated_msg ->
+  * Allow to set form of the table, multiple rc file, display next to be
-            match prepend with
+    * launched… *)
-            | "* " -> Messages.ok concatenated_msg
+let run ?rc () =
-            | "  " -> Messages.tips concatenated_msg
+  let rc_numbered =
-            | _ -> assert false)
+    File_com.init_rc ()
+    |> fun rc -> rc.progs
+    |> List.mapi ~f:(fun i item -> ( item, i ))
+  in
+  let tmp : Tmp_file.t = Tmp_file.init () in
+  Tmp_file.get_accurate_log ~tmp ()
+  (* Generate list to feed the table,
+   * XXX assuming all will be in the right order *)
+  |> List.map ~f:(function
+    ( cmd, number ) ->
+      [ (* Number of a command in rc file, command, number of launch *)
+        (List.Assoc.find_exn rc_numbered cmd |> Int.to_string);
+        cmd;
+        (Int.to_string number)
+      ])
+  |> Textutils.Ascii_table.simple_list_table
+    ~display:Textutils.Ascii_table.Display.column_titles
+    [ "Id" ; "Command" ; "Number of launch" ]
 ;;
 ;;
 
 
-(* Function which list *)
-let run ~(rc:File_com.t) =
-    List.iteri rc.Settings_t.progs ~f:(fun i item ->
-        disp_cmd_num (Tmp_file.get_current ()) i item)
-;;

+ 1 - 1
src/remove_command.ml

@@ -75,5 +75,5 @@ let run ~(rc:File_com.t) n_to_remove =
     File_com.write updated_rc;
     File_com.write updated_rc;
     (* Display the result *)
     (* Display the result *)
     let reread_rc = File_com.init_rc () in
     let reread_rc = File_com.init_rc () in
-    List_rc.run ~rc:reread_rc
+    List_rc.run ~rc:reread_rc ()
 ;;
 ;;