fixed bugs on linux

This commit is contained in:
Productive2 2021-02-19 14:35:41 +01:00
parent 2453283ad9
commit 0445f89e46
4 changed files with 9 additions and 8 deletions

View File

@ -46,7 +46,7 @@ proc quit*(le: LineEditor) =
le.state = esQuitting
le.events.call(jeQuit)
proc forceRedraw*(le: LineEditor) =
proc redraw*(le: LineEditor) =
le.forceRedraw = true
# constructor
@ -89,9 +89,6 @@ proc render(editor: LineEditor, wr: var TermWriter, line: int = -1, hscroll: boo
0
)
proc clearLine(wr: var TermWriter) =
wr.clearLine()
proc fullRender(editor: LineEditor, wr: var TermWriter) =
# from the top cursor pos, it draws the entire multiline prompt, then
# moves cursor to current y
@ -100,7 +97,7 @@ proc fullRender(editor: LineEditor, wr: var TermWriter) =
if i < editor.rendered:
wr.down(1)
else:
write stdout, "\n"
wr.lf()
inc editor.rendered
var extraup = 0
@ -131,7 +128,6 @@ proc read*(editor: LineEditor): string =
while editor.state == esTyping:
# refresh current line every time
editor.render(buffer)
buffer.setCursorX(editor.content.X + editor.prompt.len())
# get key (with escapes)
buffer.flush()
@ -151,6 +147,8 @@ proc read*(editor: LineEditor): string =
editor.fullRender(buffer)
if editor.forceRedraw:
editor.forceRedraw = false
else:
editor.render(buffer)
editor.events.call(jePostRead)

View File

@ -37,19 +37,23 @@ proc bindHistory*(ed: LineEditor, h: History, useShift: bool = false) =
let res = h.delta(-1)
if res.isSome():
ed.content = res.get()
ed.redraw()
ed.bindKey(downkey):
let res = h.delta(1)
if res.isSome():
ed.content = res.get()
ed.redraw()
ed.bindKey(homekey):
let res = h.toStart()
if res.isSome():
ed.content = res.get()
ed.redraw()
ed.bindKey(endKey):
let res = h.toStart()
if res.isSome():
ed.content = res.get()
ed.redraw()

View File

@ -18,5 +18,3 @@ proc renderLine*(wr: var TermWriter, prompt: string, content: string, hscroll: i
content = content[lower..upper]
wr &= content

View File

@ -55,6 +55,7 @@ proc clearLine*(wr: var TermWriter) =
wr &= ($27.char & "[1M" & $27.char & "[1L")
else:
wr &= ($27.char & "[2K")
wr.cr()
proc setCursorX*(wr: var TermWriter, x: int) =
when defined(windows):