Browse Source

Change Message.confirm to make it work.

 + Problem was
  + needed to flush stdout
  + more debug to limit future problems
Leo 9 years ago
parent
commit
44b96bd014
3 changed files with 14 additions and 4 deletions
  1. 10 4
      src/messages.ml
  2. 1 0
      src/messages.mli
  3. 3 0
      src/tmp_file.ml

+ 10 - 4
src/messages.ml

@@ -131,6 +131,10 @@ let warning message =
 
 (* Type for the answers *)
 type answer = Yes | No;;
+(* Usefull to display result *)
+let answer2str = function
+  Yes -> "Yes" | No -> "No"
+;;
 (* State of the program, if you should always answer yes, no or ask to the user
  * (default)*)
 (* TODO Put it in Const *)
@@ -146,13 +150,15 @@ let check_assume_yes ~f =
 (* Get confirmation
  * TODO:
    * allow option like -y
-   * test it *)
+   * test it (display, line return, etc...) *)
 let rec confirm info =
   check_assume_yes ~f:(fun () ->
     print ~color:Cyan ~style:Normal info;
-    print ~color:Cyan ~style:Normal "Are you sure ? (Yes/No): ";
-    In_channel.(input_line ~fix_win_eol:true stdin)
-    |> (function
+    print ~color:Cyan ~style:Normal "\nAre you sure ? (Yes/No): ";
+    (* XXX Be sure to show the message *)
+    Out_channel.(flush stdout);
+    let str_answer = In_channel.(input_line ~fix_win_eol:true stdin) in
+    str_answer |> (function
       | Some "Y" | Some "y" | Some "Yes" | Some "YES" | Some "yes" -> Yes
       | Some "N" | Some "n" | Some "No" | Some "NO" | Some "no" -> No
       | Some _ | None ->

+ 1 - 0
src/messages.mli

@@ -40,6 +40,7 @@ val warning : string -> unit
 val ok : string -> unit
 val tips : string -> unit
 type answer = Yes | No
+val answer2str : answer -> string
 val confirm : string -> answer
 
 val reset : unit -> unit

+ 3 - 0
src/tmp_file.ml

@@ -212,6 +212,7 @@ let reset2num ~rc num =
 
 (* Reset all command *)
 let reset_all () =
+  Messages.debug "Preparing to reset all";
   let reset_without_ask () =
     (* Make sure that file exists, otherwise strange things appears *)
     let tmp = init () in
@@ -219,7 +220,9 @@ let reset_all () =
     let name = Lazy.force !Const.rc_file in
     write Tmp_biniou_t.{ tmp with rc = List.Assoc.add tmp.rc name [] }
   in
+  Messages.debug "Asking question";
   Messages.confirm "You will lose number of launch for every command."
+  |> (fun answer -> sprintf "Answer %s" (Messages.answer2str answer) |> Messages.debug; answer) (* Spy *)
     |> function
       Messages.Yes -> reset_without_ask ()
       | Messages.No -> ()