jale/examples/editor.nim

32 lines
638 B
Nim
Raw Permalink Normal View History

2021-02-19 11:27:27 +01:00
import jale/plugin/defaults
2021-02-24 00:31:58 +01:00
import jale/plugin/viewprotector
2021-02-19 11:27:27 +01:00
import jale/editor
import jale/templates
import jale/multiline
import terminal
2021-02-19 11:27:27 +01:00
import strutils
2021-02-18 21:51:44 +01:00
import os
2021-02-18 21:51:44 +01:00
eraseScreen()
setCursorPos(stdout, 0,0)
let e = newLineEditor()
2021-02-18 21:51:44 +01:00
if paramCount() > 0:
let arg = paramStr(1)
if fileExists(arg):
2021-02-18 22:25:13 +01:00
e.content = readFile(arg).fromString()
2021-02-18 22:27:36 +01:00
var save = false
2021-02-18 21:51:44 +01:00
e.bindKey("ctrl+s"):
e.finish()
2021-02-18 22:27:36 +01:00
save = true
e.prompt = ""
2021-02-19 15:58:35 +01:00
e.populateDefaults(enterSubmits = false, ctrlForVerticalMove = false)
2021-02-24 00:31:58 +01:00
e.setViewBehavior(vbFullscreen)
e.scrollMode = sbAllScroll
2021-02-18 21:51:44 +01:00
let result = e.read()
2021-02-18 22:27:36 +01:00
if save and paramCount() > 0:
2021-02-18 21:51:44 +01:00
writeFile(paramStr(1), result)