diff --git a/src/AbstractMenu.jl b/src/AbstractMenu.jl index 3bf9abd47b50f..9c9bd0b986716 100644 --- a/src/AbstractMenu.jl +++ b/src/AbstractMenu.jl @@ -102,6 +102,22 @@ varies based on menu type. request(m::AbstractMenu) = request(terminal, m) function request(term::Base.Terminals.TTYTerminal, m::AbstractMenu) + + function advance_cursor() + if cursor < length(options(m)) + # move selection up + cursor += 1 + # scroll page + if cursor >= m.pagesize + m.pageoffset && m.pagesize + m.pageoffset < length(options(m)) + m.pageoffset += 1 + end + elseif CONFIG[:scroll_wrap] + # wrap to top + cursor = 1 + m.pageoffset = 0 + end + end + cursor = 1 menu_header = header(m) @@ -133,19 +149,7 @@ function request(term::Base.Terminals.TTYTerminal, m::AbstractMenu) end elseif c == Int(ARROW_DOWN) - - if cursor < length(options(m)) - # move selection up - cursor += 1 - # scroll page - if cursor >= m.pagesize + m.pageoffset && m.pagesize + m.pageoffset < length(options(m)) - m.pageoffset += 1 - end - elseif CONFIG[:scroll_wrap] - # wrap to top - cursor = 1 - m.pageoffset = 0 - end + advance_cursor() elseif c == Int(PAGE_UP) # If we're at the bottom, move the page 1 less to move the cursor up from @@ -172,6 +176,8 @@ function request(term::Base.Terminals.TTYTerminal, m::AbstractMenu) elseif c == 13 # # will break if pick returns true pick(m, cursor) && break + advance_cursor() + elseif c == UInt32('q') cancel(m) break diff --git a/src/MultiSelectMenu.jl b/src/MultiSelectMenu.jl index 05ec6e1799747..50b9685700cd7 100644 --- a/src/MultiSelectMenu.jl +++ b/src/MultiSelectMenu.jl @@ -9,7 +9,7 @@ A menu that allows a user to select a multiple options from a list. ```julia julia> request(MultiSelectMenu(options)) Select the fruits you like: -[press: d=done, a=all, n=none] +[press: d=done, a=all, n=none, =select] [ ] apple > [X] orange [X] grape @@ -82,7 +82,7 @@ function pick(menu::MultiSelectMenu, cursor::Int) push!(menu.selected, cursor) end - return false #break out of the menu + return false #don't break out of the menu end function writeLine(buf::IOBuffer, menu::MultiSelectMenu, idx::Int, cursor::Bool, term_width::Int) diff --git a/test/multiselect_menu.jl b/test/multiselect_menu.jl index 549fddd2e8c78..d0eda4c7c7ef0 100644 --- a/test/multiselect_menu.jl +++ b/test/multiselect_menu.jl @@ -33,4 +33,4 @@ TerminalMenus.writeLine(buf, multi_menu, 1, true, term_width) # Test SDTIN multi_menu = MultiSelectMenu(string.(1:10)) -@test simulateInput(Set([1,2]), multi_menu, :enter, :down, :enter, 'd') +@test simulateInput(Set([1,2]), multi_menu, :enter, :enter, 'd')