multiple lines scrolling together horizontally

This commit is contained in:
Art 2022-12-29 19:01:34 +01:00
parent f1602d0fb0
commit 2452633e32
Signed by: prod2
GPG Key ID: F3BB5A97A70A8DDE
1 changed files with 13 additions and 17 deletions

View File

@ -37,6 +37,15 @@ proc render*(textBuffer: TextBuffer, termBuffer: Buffer, prompt: string, scroll:
termBuffer.redraw()
return # nothing will fit anyways
const scrollOffset = 2
# right scroll
if x - scroll.x >= maxTextLen - scrollOffset:
scroll.x = x - maxTextLen + scrollOffset
# left scroll
if x - scroll.x < 0:
scroll.x = x
# left scroll on backspace - TODO IMPLEMENT
for i in 0..lines.high():
let line = lines[i]
if i == 0:
@ -44,23 +53,10 @@ proc render*(textBuffer: TextBuffer, termBuffer: Buffer, prompt: string, scroll:
else:
termBuffer.write(" ".repeat(promptLen))
let lineLen = line.len()
if lineLen < maxTextLen - 1:
scroll.x = 0
termBuffer.write(line)
else:
const scrollOffset = 2
# horizontal scroll
# right scroll
if x - scroll.x >= maxTextLen - scrollOffset:
scroll.x = x - maxTextLen + scrollOffset
# left scroll
if x - scroll.x < 0:
scroll.x = x
# left scroll
# keep what's in range
let fromPos = scroll.x
let toPos = min(scroll.x+maxTextLen-2, line.high())
# keep what's in range
let fromPos = scroll.x
let toPos = min(scroll.x+maxTextLen-2, line.high())
if fromPos <= line.high():
termBuffer.write(line[fromPos..toPos])
termBuffer.newLine()
termBuffer.setCursorPos(x + promptLen - scroll.x, y - scroll.y)