28 lines
831 B
Nim
28 lines
831 B
Nim
|
# takes a text buffer and a terminal buffer (terminalUtils/buffer)
|
||
|
# when render() is called, rewrites the terminal buffer completely as a function of
|
||
|
# of the text buffer
|
||
|
|
||
|
import textBuffer
|
||
|
import terminalUtils/buffer
|
||
|
import terminalUtils/terminalGetInfo
|
||
|
|
||
|
proc render*(textBuffer: TextBuffer, termBuffer: Buffer, prompt: string) =
|
||
|
# we are free to "redraw" everything everytime
|
||
|
# since termBuffer double buffers
|
||
|
|
||
|
# resizing the buffer if needed
|
||
|
let lineCount = textBuffer.getLineCount()
|
||
|
let termWidth = termGetWidth()
|
||
|
let termHeight = termGetHeight() # TODO
|
||
|
|
||
|
let (bufWidth, bufHeight) = termBuffer.getSize()
|
||
|
|
||
|
|
||
|
termBuffer.clearLine()
|
||
|
termBuffer.write(prompt)
|
||
|
termBuffer.write(textBuffer.getLine())
|
||
|
let (x, y) = textBuffer.getCursorPos()
|
||
|
termBuffer.setCursorPos(x + prompt.len(), y)
|
||
|
termBuffer.redraw()
|
||
|
|