Skip to content

Commit

Permalink
Add news, docs and test to keybindings in RadioMenu
Browse files Browse the repository at this point in the history
Originally introduced in JuliaLang#41576
  • Loading branch information
jonas-schulze committed Aug 9, 2021
1 parent 9665d2a commit ae6f06e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Standard library changes
#### Random

#### REPL
* `RadioMenu` now supports optional `keybindings` to directly select options ([#41576]).

#### SparseArrays

Expand Down
8 changes: 7 additions & 1 deletion stdlib/REPL/src/TerminalMenus/RadioMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ end

"""
RadioMenu(options::Array{String,1}; pagesize::Int=10, kwargs...)
RadioMenu(options::Array{String,1}; pagesize::Int=10,
keybindings::Vector{Char}=Char[],
kwargs...)
Create a RadioMenu object. Use `request(menu::RadioMenu)` to get user input.
`request()` returns an `Int` which is the index of the option selected by the
Expand All @@ -41,8 +43,12 @@ user.
- `options::Array{String, 1}`: Options to be displayed
- `pagesize::Int=10`: The number of options to be displayed at one time, the menu will scroll if length(options) > pagesize
- `keybindings::Vector{Char}=Char[]`: Shortcuts to pick corresponding entry from `options`
Any additional keyword arguments will be passed to [`TerminalMenus.Config`](@ref).
!!! compat "Julia 1.8"
The `keybindings` argument requires Julia 1.8 or later.
"""
function RadioMenu(options::Array{String,1}; pagesize::Int=10, warn::Bool=true, keybindings::Vector{Char}=Char[], kwargs...)
length(options) < 1 && error("RadioMenu must have at least one option")
Expand Down
2 changes: 2 additions & 0 deletions stdlib/REPL/test/TerminalMenus/radio_menu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ radio_menu = RadioMenu(["single option"], charset=:ascii)
@test simulate_input(1, radio_menu, :up, :up, :down, :up, :enter)
radio_menu = RadioMenu(string.(1:3), pagesize=1, charset=:ascii)
@test simulate_input(3, radio_menu, :down, :down, :down, :down, :enter)
radio_menu = RadioMenu(["apple", "banana", "cherry"]; keybindings=collect('a':'c'), charset=:ascii)
@test simulate_input(2, radio_menu, 'b')

0 comments on commit ae6f06e

Please sign in to comment.