simplify rdstdin (#18382)
This commit is contained in:
parent
808db3b284
commit
6387e28963
1 changed files with 4 additions and 10 deletions
|
|
@ -52,16 +52,6 @@ elif defined(genode):
|
||||||
else:
|
else:
|
||||||
import linenoise
|
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 {.
|
proc readLineFromStdin*(prompt: string, line: var string): bool {.
|
||||||
tags: [ReadIOEffect, WriteIOEffect].} =
|
tags: [ReadIOEffect, WriteIOEffect].} =
|
||||||
var buffer = linenoise.readLine(prompt)
|
var buffer = linenoise.readLine(prompt)
|
||||||
|
|
@ -73,3 +63,7 @@ else:
|
||||||
historyAdd(buffer)
|
historyAdd(buffer)
|
||||||
linenoise.free(buffer)
|
linenoise.free(buffer)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
proc readLineFromStdin*(prompt: string): string {.inline.} =
|
||||||
|
if not readLineFromStdin(prompt, result):
|
||||||
|
raise newException(IOError, "Linenoise returned nil")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue