add linenoise.readLineStatus to get status (eg: ctrl-D or ctrl-C) (#16977)
* add linenoise.readLineStatus to get status (eg: ctrl-D or ctrl-C) * changelog
This commit is contained in:
parent
49b64e8dc7
commit
630f867bd7
5 changed files with 77 additions and 15 deletions
|
|
@ -12,16 +12,18 @@
|
|||
## (e.g. you can navigate with the arrow keys). On Windows ``system.readLine``
|
||||
## is used. This suffices because Windows' console already provides the
|
||||
## wanted functionality.
|
||||
##
|
||||
## **Examples:**
|
||||
##
|
||||
## .. code-block:: nim
|
||||
## echo readLineFromStdin("Is Nim awesome? (Y/n):")
|
||||
## var userResponse: string
|
||||
## doAssert readLineFromStdin("How are you?:", line = userResponse)
|
||||
## echo userResponse
|
||||
|
||||
when defined(Windows):
|
||||
runnableExamples:
|
||||
if false:
|
||||
echo readLineFromStdin("Is Nim awesome? (Y/n): ")
|
||||
var line: string
|
||||
while true:
|
||||
let ok = readLineFromStdin("How are you? ", line)
|
||||
if not ok: break # ctrl-C or ctrl-D will cause a break
|
||||
if line.len > 0: echo line
|
||||
echo "exiting"
|
||||
|
||||
when defined(windows):
|
||||
proc readLineFromStdin*(prompt: string): string {.
|
||||
tags: [ReadIOEffect, WriteIOEffect].} =
|
||||
## Reads a line from stdin.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue