mirror of https://github.com/japl-lang/jale.git
some fixes
This commit is contained in:
parent
3dd77ea1d9
commit
3fd83a9043
|
@ -39,6 +39,10 @@ proc finish*(le: LineEditor) =
|
||||||
# can be overwritten to false, inside the event
|
# can be overwritten to false, inside the event
|
||||||
le.events.call(jeFinish)
|
le.events.call(jeFinish)
|
||||||
|
|
||||||
|
proc quit*(le: LineEditor) =
|
||||||
|
le.finished = true
|
||||||
|
le.events.call(jeQuit)
|
||||||
|
|
||||||
proc forceRedraw*(le: LineEditor) =
|
proc forceRedraw*(le: LineEditor) =
|
||||||
le.forceRedraw = true
|
le.forceRedraw = true
|
||||||
|
|
||||||
|
@ -115,7 +119,6 @@ proc read*(editor: LineEditor): string =
|
||||||
# starts at the top, full render moves it into the right y
|
# starts at the top, full render moves it into the right y
|
||||||
editor.fullRender()
|
editor.fullRender()
|
||||||
|
|
||||||
|
|
||||||
while not editor.finished:
|
while not editor.finished:
|
||||||
|
|
||||||
# refresh current line every time
|
# refresh current line every time
|
||||||
|
@ -143,6 +146,5 @@ proc read*(editor: LineEditor): string =
|
||||||
|
|
||||||
# move cursor to end
|
# move cursor to end
|
||||||
editor.moveCursorToEnd()
|
editor.moveCursorToEnd()
|
||||||
|
result = editor.content.getContent()
|
||||||
editor.reset()
|
editor.reset()
|
||||||
|
|
||||||
return editor.content.getContent()
|
|
||||||
|
|
|
@ -2,11 +2,23 @@ import ../plugin/defaults
|
||||||
import ../editor
|
import ../editor
|
||||||
import ../strutils
|
import ../strutils
|
||||||
import ../templates
|
import ../templates
|
||||||
|
import ../multiline
|
||||||
|
|
||||||
import terminal
|
import terminal
|
||||||
|
import os
|
||||||
|
|
||||||
|
eraseScreen()
|
||||||
|
setCursorPos(stdout, 0,0)
|
||||||
let e = newLineEditor()
|
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.prompt = ""
|
||||||
e.populateDefaults(enterSubmits = false)
|
e.populateDefaults(enterSubmits = false, shiftForVerticalMove = false)
|
||||||
let input = e.read()
|
let result = e.read()
|
||||||
|
if paramCount() > 0:
|
||||||
|
writeFile(paramStr(1), result)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
good
|
||||||
|
Hello there
|
||||||
|
|
||||||
|
heee
|
|
@ -157,10 +157,13 @@ proc serialize*(ml: Multiline, sep: string = r"\n", replaceBS: bool = true): str
|
||||||
result &= line.content & sep
|
result &= line.content & sep
|
||||||
result[0..result.high() - sep.len()]
|
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()
|
result = newMultiline()
|
||||||
for line in str.split(sep):
|
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.y = result.high()
|
||||||
result.x = result.lineLen()
|
result.x = result.lineLen()
|
||||||
|
|
|
@ -14,11 +14,11 @@ proc bindInput*(editor: LineEditor) =
|
||||||
|
|
||||||
proc bindTerminate*(editor: LineEditor) =
|
proc bindTerminate*(editor: LineEditor) =
|
||||||
editor.bindKey("ctrl+c"):
|
editor.bindKey("ctrl+c"):
|
||||||
editor.finish()
|
editor.quit()
|
||||||
|
|
||||||
editor.bindKey("ctrl+d"):
|
editor.bindKey("ctrl+d"):
|
||||||
if editor.content.getContent() == "":
|
if editor.content.getContent() == "":
|
||||||
editor.finish()
|
editor.quit()
|
||||||
|
|
||||||
|
|
||||||
proc populateDefaults*(editor: LineEditor, enterSubmits = true, shiftForVerticalMove = true) =
|
proc populateDefaults*(editor: LineEditor, enterSubmits = true, shiftForVerticalMove = true) =
|
||||||
|
|
Loading…
Reference in New Issue