From e2a67780300e8ef172b241e8802c48316ea5eeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnar=20Farneb=C3=A4ck?= Date: Mon, 30 Nov 2020 19:31:32 +0100 Subject: [PATCH] Properly handle move up zero lines in TerminalMenus. --- stdlib/REPL/src/TerminalMenus/AbstractMenu.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl index 961d6c3db7cb7..4dff0c31595ee 100644 --- a/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl +++ b/stdlib/REPL/src/TerminalMenus/AbstractMenu.jl @@ -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 @@ -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`