Skip to content

Commit d6f3476

Browse files
jonas-schulzeKristofferC
authored andcommitted
Add news, docs and test to keybindings in RadioMenu (#42344)
1 parent 03cee00 commit d6f3476

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Standard library changes
8181
#### Random
8282

8383
#### REPL
84-
84+
* `RadioMenu` now supports optional `keybindings` to directly select options ([#41576]).
8585
* ` ?(x, y` followed by TAB displays all methods that can be called
8686
with arguments `x, y, ...`. (The space at the beginning prevents entering help-mode.)
8787
`MyModule.?(x, y` limits the search to `MyModule`. TAB requires that at least one

stdlib/REPL/src/TerminalMenus/RadioMenu.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ end
3131

3232
"""
3333
34-
RadioMenu(options::Array{String,1}; pagesize::Int=10, kwargs...)
34+
RadioMenu(options::Array{String,1}; pagesize::Int=10,
35+
keybindings::Vector{Char}=Char[],
36+
kwargs...)
3537
3638
Create a RadioMenu object. Use `request(menu::RadioMenu)` to get user input.
3739
`request()` returns an `Int` which is the index of the option selected by the
@@ -41,8 +43,12 @@ user.
4143
4244
- `options::Array{String, 1}`: Options to be displayed
4345
- `pagesize::Int=10`: The number of options to be displayed at one time, the menu will scroll if length(options) > pagesize
46+
- `keybindings::Vector{Char}=Char[]`: Shortcuts to pick corresponding entry from `options`
4447
4548
Any additional keyword arguments will be passed to [`TerminalMenus.Config`](@ref).
49+
50+
!!! compat "Julia 1.8"
51+
The `keybindings` argument requires Julia 1.8 or later.
4652
"""
4753
function RadioMenu(options::Array{String,1}; pagesize::Int=10, warn::Bool=true, keybindings::Vector{Char}=Char[], kwargs...)
4854
length(options) < 1 && error("RadioMenu must have at least one option")

stdlib/REPL/test/TerminalMenus/radio_menu.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ radio_menu = RadioMenu(["single option"], charset=:ascii)
5050
@test simulate_input(1, radio_menu, :up, :up, :down, :up, :enter)
5151
radio_menu = RadioMenu(string.(1:3), pagesize=1, charset=:ascii)
5252
@test simulate_input(3, radio_menu, :down, :down, :down, :down, :enter)
53+
radio_menu = RadioMenu(["apple", "banana", "cherry"]; keybindings=collect('a':'c'), charset=:ascii)
54+
@test simulate_input(2, radio_menu, 'b')

0 commit comments

Comments
 (0)