Skip to content

Commit

Permalink
Do not pre-write the answer to questions with the default anwser
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Feb 4, 2025
1 parent 3a11680 commit 125f74c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dir>` failure when it is a linked switch [#6276 @btjorge - fix #6275]
Expand Down Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
1 change: 0 additions & 1 deletion src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 5 additions & 26 deletions src/core/opamConsole.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down Expand Up @@ -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 () =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 125f74c

Please sign in to comment.