☰

# std/rdstdin

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

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.

Example: cmd: -r:off

    import std/rdstdin
    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"

# Imports

linenoise

# Procs

    proc readLineFromStdin(prompt: string): string {.inline, ...raises: [IOError],
        tags: [ReadIOEffect, WriteIOEffect], forbids: [].}

  Source Edit

    proc readLineFromStdin(prompt: string; line: var string): bool {.
        ...tags: [ReadIOEffect, WriteIOEffect], raises: [], forbids: [].}

  Source Edit