diff --git a/renderer.nim b/renderer.nim index 4ae3f59..d657588 100644 --- a/renderer.nim +++ b/renderer.nim @@ -25,6 +25,7 @@ proc render*(textBuffer: TextBuffer, termBuffer: Buffer, prompt: string, scroll: if bufWidth != termWidth or bufHeight != min(lineCount, termHeight): termBuffer.resize(termWidth, min(lineCount, termHeight)) + termBuffer.clear() diff --git a/terminalUtils/buffer.nim b/terminalUtils/buffer.nim index 27a5679..d6a236a 100644 --- a/terminalUtils/buffer.nim +++ b/terminalUtils/buffer.nim @@ -1,6 +1,7 @@ import unicode import escapeSequences import sequtils +import strformat type Buffer* = ref object @@ -47,7 +48,7 @@ func getCursorPos*(buf: Buffer): (int, int) = proc setCursorPos*(buf: Buffer, x, y: int) = if x < 0 or y < 0 or x >= buf.width or y >= buf.height: - raise newException(ValueError, "Provided x or y out of bounds for SetCursorPos.") + raise newException(ValueError, &"Provided x ({x}) or y ({y}) out of bounds (x: {0}..{buf.width-1}; y: {0}..{buf.height-1}) for SetCursorPos.") buf.bufferX = x buf.bufferY = y diff --git a/textBuffer.nim b/textBuffer.nim index 64721c9..75530b1 100644 --- a/textBuffer.nim +++ b/textBuffer.nim @@ -97,9 +97,9 @@ proc enter*(buf: TextBuffer) = proc newLine*(buf: TextBuffer) = # inserts a new empty line below the current one # and moves cursor to it - # TODO fix crash inc buf.cursorY - buf.content.insert(@[], buf.cursorY) + let empty: seq[Rune] = @[] + buf.content.insert(empty, buf.cursorY) buf.cursorX = 0 proc getLineCount*(buf: TextBuffer): int =