From 125f74cc1555acc3b8448896d914a283fe04ae99 Mon Sep 17 00:00:00 2001 From: Kate Date: Mon, 11 Nov 2024 21:18:15 +0000 Subject: [PATCH] Do not pre-write the answer to questions with the default anwser --- master_changes.md | 2 ++ src/client/opamClient.ml | 1 - src/client/opamSolution.ml | 1 - src/core/opamConsole.ml | 31 +++++-------------------------- 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/master_changes.md b/master_changes.md index bc2c04e23cc..99eebfce170 100644 --- a/master_changes.md +++ b/master_changes.md @@ -36,6 +36,7 @@ users) * [BUG] Ensure the output of opam commands using a column style UI stay consistent accross environment by setting the number of columns to 80 if stdout is not a tty and if the `COLUMNS` env variable is not set [#6244 @kit-ty-kate] * Improve the messages when a package is not up-to-date on opam upgrade [#6272 @kit-ty-kate - fix #6270] * Use a non-underline uppercase character to denotate the default when asking a question [#6289 @hannesm @kit-ty-kate - fix #6288] + * Do not pre-write the answer to questions with the default anwser [#6376 @kit-ty-kate] ## Switch * [BUG] Fix `opam switch remove ` failure when it is a linked switch [#6276 @btjorge - fix #6275] @@ -162,6 +163,7 @@ users) * `OpamFormula.all_relop`: a list of all operators [#6197 @mbarbin] ## opam-core + * `OpamConsole.pause`: Ensure the function always prints a newline character at the end [#6376 @kit-ty-kate] * `OpamStd.Sys.{get_terminal_columns,uname,getconf,guess_shell_compat}`: Harden the process calls to account for failures [#6230 @kit-ty-kate - fix #6215] * `OpamStd.Sys.{uname,getconf}`: now accepts only one argument as parameter, as per their documentation [#6230 @kit-ty-kate] * `OpamStubs.get_stdout_ws_col`: new Unix-only function returning the number of columns of the current terminal window [#6244 @kit-ty-kate] diff --git a/src/client/opamClient.ml b/src/client/opamClient.ml index 14db917ed22..755ba7a2f05 100644 --- a/src/client/opamClient.ml +++ b/src/client/opamClient.ml @@ -1281,7 +1281,6 @@ let initialise_msys2 root = OpamConsole.error_and_exit `Aborted "MSYS2 failed to initialise" | `No -> OpamConsole.pause "Standing by, press enter to continue when done."; - OpamConsole.msg "\n" | `Ignore -> () | `Quit -> diff --git a/src/client/opamSolution.ml b/src/client/opamSolution.ml index 60280adf916..8a24da0368e 100644 --- a/src/client/opamSolution.ml +++ b/src/client/opamSolution.ml @@ -1215,7 +1215,6 @@ let install_sys_packages ~map_sysmap ~confirm env config sys_packages t = OpamConsole.msg "\n"; print_command sys_packages; OpamConsole.pause "Standing by, press enter to continue when done."; - OpamConsole.msg "\n"; check_again t sys_packages | `Ignore -> bypass t | `Quit -> give_up_msg (); OpamStd.Sys.exit_because `Aborted diff --git a/src/core/opamConsole.ml b/src/core/opamConsole.ml index 66d1eebc786..9c160c5ea81 100644 --- a/src/core/opamConsole.ml +++ b/src/core/opamConsole.ml @@ -473,17 +473,6 @@ let rollback_terminal nlines = Printf.printf "\027[A" done -let left_1_char = - let left_1_char_unix () = Printf.printf "\027[D%!" in - if Sys.win32 then - let f = lazy ( - match get_win32_console_shim `stdout Mode with - | Shim -> fun () -> () (* unimplemented *) - | VT100 force -> fun () -> force (); left_1_char_unix () - ) in - fun () -> Lazy.force f () - else left_1_char_unix - let displaying_status = ref false let clear_status_unix () = @@ -725,17 +714,7 @@ let header_error fmt = (* Reads a single char from the user when possible, a line otherwise *) let short_user_input ~prompt ?default ?on_eof f = let on_eof = OpamStd.Option.Op.(on_eof ++ default) in - let prompt () = match default with - | Some x when OpamStd.Sys.tty_out -> - msg "%s%s" prompt x; - left_1_char (); - carriage_delete (); - (match List.rev (OpamStd.String.split prompt '\n') with - | lastline::_ -> print_string lastline - | [] -> ()) - | _ -> - print_string prompt; flush stdout - in + let prompt () = print_string prompt; flush stdout in try if OpamStd.Sys.(not tty_out || os () = Win32 || os () = Cygwin) then let rec loop () = @@ -769,9 +748,9 @@ let short_user_input ~prompt ?default ?on_eof f = match input with | None -> loop () | Some i -> match f i with - | Some a -> - if String.length i > 0 && i.[0] <> '\027' then print_endline i; - a + | Some a when String.length i > 0 && i.[0] = '\027' -> + print_newline (); a + | Some a -> print_endline i; a | None -> loop () in let attr = tcgetattr stdin in @@ -801,7 +780,7 @@ let pause fmt = let prompt = OpamStd.Format.reformat s in short_user_input ~prompt ~default:"" (function - | "\027" -> OpamStd.Sys.exit_because `Aborted + | "\027" -> print_newline (); OpamStd.Sys.exit_because `Aborted | _ -> Some ())) fmt else