Skip to content

Commit

Permalink
Merge pull request #3 from christopher-dG/master
Browse files Browse the repository at this point in the history
Make all `request` calls start at the first option
  • Loading branch information
Nicholas Paul authored Jul 17, 2017
2 parents 0df1d6f + 066154d commit 5c69990
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/AbstractMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function request(m::AbstractMenu)

menu_header = header(m)
if menu_header != ""
println(header(m))
println(menu_header)
end

printMenu(m, cursor, init=true)
Expand Down Expand Up @@ -161,7 +161,7 @@ function request(m::AbstractMenu)
finally
# always disable raw mode even even if there is an
# exception in the above loop
print("\x1b[?25h") #unhide cursor
print("\x1b[?25h") # unhide cursor
disableRawMode()
end
println()
Expand All @@ -174,7 +174,7 @@ end
request(msg::AbstractString, m::AbstractMenu)
Shorthand for `println(msg); request(m)`.
Shorthand for `println(msg); request(m)`.
"""
function request(msg::AbstractString, m::AbstractMenu)
println(msg)
Expand All @@ -185,20 +185,24 @@ end

# The generic printMenu function is used for displaying the state of a
# menu to the screen. Menus must implement `writeLine` and `options`
# and have feilds `pagesize::Int` and `pageoffset::Int` as part of
# and have fields `pagesize::Int` and `pageoffset::Int` as part of
# their type definition
function printMenu(m::AbstractMenu, cursor::Int; init::Bool=false)
buf = IOBuffer()

# Move the cursor to the begining of where it should print
# Move the cursor to the beginning of where it should print
# Don't do this on the initial print
lines = m.pagesize-1
!init && print(buf, "\x1b[999D\x1b[$(lines)A")
if init
m.pageoffset = 0
else
print(buf, "\x1b[999D\x1b[$(lines)A")
end

for i in (m.pageoffset+1):(m.pageoffset + m.pagesize)
print(buf, "\x1b[2K")

if i == m.pageoffset+1 && m.pageoffset > 0
if i == m.pageoffset+1 && m.pageoffset > 0
# first line && scrolled past first entry
print(buf, CONFIG[:up_arrow])
elseif i == m.pagesize+m.pageoffset && i != length(options(m))
Expand Down

0 comments on commit 5c69990

Please sign in to comment.