all repos — minline @ 908db5bc2bca7beb9a6b277bbd107ee5ff8094aa

A minimalist but highly-customizable line editing library.

Fixed compilation errors with Nim 0.19.0.
h3rald h3rald@h3rald.com
Sun, 18 Nov 2018 18:12:09 +0100
commit

908db5bc2bca7beb9a6b277bbd107ee5ff8094aa

parent

c63382b8af73aed0005079c23bfe7a6e00234b34

1 files changed, 9 insertions(+), 9 deletions(-)

jump to
M nimline.nimnimline.nim

@@ -148,13 +148,13 @@ h.queue.addLast s

proc previous(h: var LineHistory): string = if h.queue.len == 0 or h.position <= 0: - return nil + return "" h.position.dec result = h.queue[h.position] proc next(h: var LineHistory): string = if h.queue.len == 0 or h.position >= h.queue.len-1: - return nil + return "" h.position.inc result = h.queue[h.position]

@@ -259,14 +259,14 @@ let diff = ed.line.text.len - ed.line.position

stdout.cursorForward(diff) ed.line.position = ed.line.text.len -proc historyInit*(size = 256, file: string = nil): LineHistory = +proc historyInit*(size = 256, file: string = ""): LineHistory = ## Creates a new **LineHistory** object with the specified **size** and **file**. result.file = file result.queue = initDeque[string](size) result.position = 0 result.tainted = false result.max = size - if file.isNil: + if file == "": return if result.file.fileExists: let lines = result.file.readFile.split("\n")

@@ -280,7 +280,7 @@

proc historyAdd*(ed: var LineEditor, force = false) = ## Adds the current editor line to the history. If **force** is set to **true**, the line will be added even if it's blank. ed.history.add ed.line.text, force - if ed.history.file.isNil: + if ed.history.file == "": return ed.history.file.writeFile(toSeq(ed.history.queue.items).join("\n"))

@@ -288,7 +288,7 @@ proc historyPrevious*(ed: var LineEditor) =

## Replaces the contents of the current line with the previous line stored in the history (if any). ## The current line will be added to the history and the hisory will be marked as *tainted*. let s = ed.history.previous - if s.isNil: + if s == "": return let pos = ed.history.position var current: int

@@ -305,7 +305,7 @@

proc historyNext*(ed: var LineEditor) = ## Replaces the contents of the current line with the following line stored in the history (if any). let s = ed.history.next - if s.isNil: + if s == "": return ed.changeLine(s)

@@ -395,7 +395,7 @@ proc lineText*(ed: LineEditor): string =

## Returns the contents of the current line. return ed.line.text -proc initEditor*(mode = mdInsert, historySize = 256, historyFile: string = nil): LineEditor = +proc initEditor*(mode = mdInsert, historySize = 256, historyFile: string = ""): LineEditor = ## Creates a **LineEditor** object. result.mode = mode result.history = historyInit(historySize, historyFile)

@@ -674,7 +674,7 @@ # quit(0)

# #testChar() proc testLineEditor() = - var ed = initEditor(historyFile = nil) + var ed = initEditor(historyFile = "") while true: echo "---", ed.readLine("-> "), "---"