import std/strutils # strip, split, join
import std/strformat # &"Hello {name}!"
import std/rdstdin # for inputExtra()
# simple solution
proc input(prompt: string = ""): string =
stdout.write(prompt)
stdin.readLine()
# advanced solution
proc inputExtra(prompt: string = ""): string =
## Like Python's ``input()`` function. Arrows also work.
##
## You can also specify a prompt.
## The extra thing is that the arrows also work, like in Bash.
## In Python you can have the same effect if you ``import readline``.
## If the user presses Ctrl+C or Ctrl+D, an EOFError exception is raised
## that you catch on the caller side.
##
## .. code-block:: nim
##
## try:
## let name = inputExtra("Name: ")
## except EOFError:
## echo "user abort" # Ctrl+C or Ctrl+D was pressed
var line: string = ""
let val = readLineFromStdin(prompt, line) # line is modified
if not val:
raise newException(EOFError, "abort")
line
proc main() =
let name = inputExtra("Name: ").strip
echo &"Hello {name}!"