This module contains code for reading from stdin. On UNIX the linenoise library is wrapped and set up to provide default key bindings (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.
VK_SHIFT = 16
VK_CONTROL = 17
VK_MENU = 18
KEY_EVENT = 1
proc readLineFromStdin(prompt: string): TaintedString {. tags: [ReadIOEffect, WriteIOEffect], raises: [IOError, EOFError].}
proc readLineFromStdin(prompt: string; line: var TaintedString): bool {. tags: [ReadIOEffect, WriteIOEffect], raises: [IOError].}
nil
! May throw an IO exception. A line of text may be delimited by CR
, LF
or CRLF
. The newline character(s) are not part of the returned string. Returns false
if the end of the file has been reached, true
otherwise. If false
is returned line contains no new data. proc readConsoleInputW(hConsoleInput: Handle; lpBuffer: var INPUT_RECORD; nLength: uint32; lpNumberOfEventsRead: var uint32): WINBOOL {. stdcall, dynlib: "kernel32", importc: "ReadConsoleInputW".}
proc readPasswordFromStdin(prompt: string; password: var TaintedString): bool {. tags: [ReadIOEffect, WriteIOEffect], raises: [IOError].}
nil
! Returns false
if the end of the file has been reached, true
otherwise. proc readPasswordFromStdin(prompt: string): TaintedString {.raises: [IOError], tags: [ReadIOEffect, WriteIOEffect].}
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/rdstdin.html