Skip to content

Commit

Permalink
Extend OpamConsole.menu to support 35 options
Browse files Browse the repository at this point in the history
The Git-for-Windows and Cygwin options mean at least one Windows user is
capable of blowing the previous limit of 9 menu items quite trivally.
1-9 used as before with a-z used for the remaining items.
  • Loading branch information
dra27 authored and kit-ty-kate committed Jun 6, 2024
1 parent 5c582e1 commit 4d119e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ users)
* `OpamStubs.readRegistry`: on Windows, complements `OpamStubs.writeRegistry` [#5963 @dra27]
* `OpamStubs.get_initial_environment`: on Windows, returns the pristine environment for new shells [#5963 @dra27]
* `OpamConsole`: Add `formatted_errmsg` [#5999 @kit-ty-kate]
* `OpamConsole.menu` now supports up to 35 menu items [#5992 @dra27]
8 changes: 6 additions & 2 deletions src/core/opamConsole.ml
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,13 @@ let print_table ?cut oc ~sep table =
List.iter (fun l -> print_line (cleanup_trailing l)) table

let menu ?default ?unsafe_yes ?yes ~no ~options fmt =
assert (List.length options < 10);
assert (List.length options < 36);
let options_nums =
List.mapi (fun n (ans, _) -> ans, string_of_int (n+1)) options
let option_of_index n =
(* NOTE: 1..9 (starts at ASCII 49) & a..z (starts at ASCII 97) *)
(String.make 1 (char_of_int (if n < 9 then n+49 else n+97)))
in
List.mapi (fun n (ans, _) -> ans, option_of_index n) options
in
let nums_options = List.map (fun (a, n) -> n, a) options_nums in
let rec prev_option a0 = function
Expand Down
2 changes: 1 addition & 1 deletion src/core/opamConsole.mli
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ val confirm:
options are set.
[no] is the option to choose otherwise, when non interactive, on [escape].
[default] is the option to choose on an active empty input ("\n").
Max 9 options. *)
Max 35 options. *)
val menu:
?default:'a -> ?unsafe_yes:'a -> ?yes:'a -> no:'a ->
options:('a * string) list ->
Expand Down

0 comments on commit 4d119e1

Please sign in to comment.