some fixes

This commit is contained in:
Productive2 2021-02-18 21:51:44 +01:00
parent 3dd77ea1d9
commit 3fd83a9043
5 changed files with 31 additions and 9 deletions

View File

@ -39,6 +39,10 @@ proc finish*(le: LineEditor) =
# can be overwritten to false, inside the event
le.events.call(jeFinish)
proc quit*(le: LineEditor) =
le.finished = true
le.events.call(jeQuit)
proc forceRedraw*(le: LineEditor) =
le.forceRedraw = true
@ -115,7 +119,6 @@ proc read*(editor: LineEditor): string =
# starts at the top, full render moves it into the right y
editor.fullRender()
while not editor.finished:
# refresh current line every time
@ -143,6 +146,5 @@ proc read*(editor: LineEditor): string =
# move cursor to end
editor.moveCursorToEnd()
result = editor.content.getContent()
editor.reset()
return editor.content.getContent()

View File

@ -2,11 +2,23 @@ import ../plugin/defaults
import ../editor
import ../strutils
import ../templates
import ../multiline
import terminal
import os
eraseScreen()
setCursorPos(stdout, 0,0)
let e = newLineEditor()
if paramCount() > 0:
let arg = paramStr(1)
if fileExists(arg):
e.content = readFile(arg).deserialize(replaceBS = false)
e.bindKey("ctrl+s"):
e.finish()
e.prompt = ""
e.populateDefaults(enterSubmits = false)
let input = e.read()
e.populateDefaults(enterSubmits = false, shiftForVerticalMove = false)
let result = e.read()
if paramCount() > 0:
writeFile(paramStr(1), result)

5
examples/test.text Normal file
View File

@ -0,0 +1,5 @@
good
Hello there
heee

View File

@ -157,10 +157,13 @@ proc serialize*(ml: Multiline, sep: string = r"\n", replaceBS: bool = true): str
result &= line.content & sep
result[0..result.high() - sep.len()]
proc deserialize*(str: string, sep: string = r"\n"): Multiline =
proc deserialize*(str: string, sep: string = r"\n", replaceBS: bool = true): Multiline =
result = newMultiline()
for line in str.split(sep):
result.lines.add(newLine(line.replace(r"\\", r"\")))
if replaceBS:
result.lines.add(newLine(line.replace(r"\\", r"\")))
else:
result.lines.add(newLine(line))
result.y = result.high()
result.x = result.lineLen()

View File

@ -14,11 +14,11 @@ proc bindInput*(editor: LineEditor) =
proc bindTerminate*(editor: LineEditor) =
editor.bindKey("ctrl+c"):
editor.finish()
editor.quit()
editor.bindKey("ctrl+d"):
if editor.content.getContent() == "":
editor.finish()
editor.quit()
proc populateDefaults*(editor: LineEditor, enterSubmits = true, shiftForVerticalMove = true) =