Skip to content

Commit

Permalink
simplify rdstdin (nim-lang#18382)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour authored Jun 28, 2021
1 parent 808db3b commit 6387e28
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/impure/rdstdin.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ elif defined(genode):
else:
import linenoise

proc readLineFromStdin*(prompt: string): string {.
tags: [ReadIOEffect, WriteIOEffect].} =
var buffer = linenoise.readLine(prompt)
if isNil(buffer):
raise newException(IOError, "Linenoise returned nil")
result = $buffer
if result.len > 0:
historyAdd(buffer)
linenoise.free(buffer)

proc readLineFromStdin*(prompt: string, line: var string): bool {.
tags: [ReadIOEffect, WriteIOEffect].} =
var buffer = linenoise.readLine(prompt)
Expand All @@ -73,3 +63,7 @@ else:
historyAdd(buffer)
linenoise.free(buffer)
result = true

proc readLineFromStdin*(prompt: string): string {.inline.} =
if not readLineFromStdin(prompt, result):
raise newException(IOError, "Linenoise returned nil")

0 comments on commit 6387e28

Please sign in to comment.