Skip to content

Commit

Permalink
Add news, docs and test to keybindings in RadioMenu (JuliaLang#42344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schulze committed Sep 22, 2021
1 parent deb3fac commit b55497d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Standard library changes
#### Random

#### REPL

* `RadioMenu` now supports optional `keybindings` to directly select options ([#41576]).
* ` ?(x, y` followed by TAB displays all methods that can be called
with arguments `x, y, ...`. (The space at the beginning prevents entering help-mode.)
`MyModule.?(x, y` limits the search to `MyModule`. TAB requires that at least one
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 b55497d

Please sign in to comment.