all repos — minline @ ce72148699ddb3498712cb4eb86aeb467b1882f6

A minimalist but highly-customizable line editing library.

Minor updates
h3rald h3rald@h3rald.com
Tue, 09 Feb 2021 01:08:28 +0000
commit

ce72148699ddb3498712cb4eb86aeb467b1882f6

parent

b7f2afd22ec69c56ecf3a3e1a1e54adb3acb0dda

1 files changed, 5 insertions(+), 11 deletions(-)

jump to
M nimline.nimnimline.nim

@@ -130,9 +130,9 @@ if ed.currentLine <= 0:

return let pos = ed.line.position ed.currentLine = ed.currentLine - nn - ed.line.position = min(pos, ed.line.text.len-1) + ed.line.position = min(pos, ed.line.text.len) stdout.cursorUp(nn) - let pdiff = pos - ed.line.text.len-1; + let pdiff = pos - ed.line.text.len; if pdiff > 0: ed.back(pdiff)

@@ -153,8 +153,9 @@ if ed.currentLine >= ed.lines.len-1:

return let pos = ed.line.position ed.currentLine = ed.currentLine + nn + ed.line.position = min(pos, ed.line.text.len) stdout.cursorDown(nn) - let pdiff = pos - ed.line.text.len-1; + let pdiff = pos - ed.line.text.len; if pdiff > 0: ed.back(pdiff)

@@ -738,24 +739,17 @@ #testChar()

proc testLineEditor() = var ed = initEditor(historyFile = "") ed.newLineCallback = proc(ed: var LineEditor, prompt: string, c: int): string = - ed.printChar(c) + stdout.write("\n ") let lpar = ed.text.count("(") let rpar = ed.text.count(")") if (lpar != rpar): - stdout.write("\n" & prompt & "... ") ed.newLine() - ed.lines[ed.currentLine].text &= " " - ed.lines[ed.currentLine].position += 4 return "" else: - stdout.write("\n") ed.historyAdd() ed.historyFlush() let text = ed.text ed.lines = newSeq[Line](0) - #echo "+++" - #echo text - #echo "---" return text while true: echo ed.readLine("-> ")