Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle move up zero lines in TerminalMenus. #38630

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Properly handle move up zero lines in TerminalMenus.
  • Loading branch information
GunnarFarneback committed Nov 30, 2020
commit e2a67780300e8ef172b241e8802c48316ea5eeed
11 changes: 9 additions & 2 deletions stdlib/REPL/src/TerminalMenus/AbstractMenu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,14 @@ function printmenu(out::IO, m::AbstractMenu, cursoridx::Int; oldstate=nothing, i
# like clamp, except this takes the min if max < min
m.pageoffset = max(0, min(cursoridx - m.pagesize ÷ 2, lastoption - m.pagesize))
else
print(buf, "\x1b[999D\x1b[$(ncleared)A") # move left 999 spaces and up `ncleared` lines
print(buf, "\r")
if ncleared > 0
# Move up `ncleared` lines. However, moving up zero lines
# is interpreted as one line, so need to do this
# conditionally. (More specifically, the `0` value means
# to use the default, and for move up this is one.)
print(buf, "\x1b[$(ncleared)A")
end
end

nheaderlines = 0
Expand Down Expand Up @@ -354,7 +361,7 @@ function printmenu(out::IO, m::AbstractMenu, cursoridx::Int; oldstate=nothing, i
printcursor(buf, m, i == cursoridx)
writeline(buf, m, i, i == cursoridx)

(firstline == lastline || i != lastline) && print(buf, "\r\n")
(i != lastline) && print(buf, "\r\n")
end

newstate = nheaderlines + lastline - firstline # final line doesn't have `\n`
Expand Down