Skip to content

Commit

Permalink
advance cursor after selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Jun 12, 2018
1 parent cc8ed29 commit f6f4292
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/AbstractMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -172,6 +176,8 @@ function request(term::Base.Terminals.TTYTerminal, m::AbstractMenu)
elseif c == 13 # <enter>
# will break if pick returns true
pick(m, cursor) && break
advance_cursor()

elseif c == UInt32('q')
cancel(m)
break
Expand Down
2 changes: 1 addition & 1 deletion test/multiselect_menu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit f6f4292

Please sign in to comment.