# Prelude.Interactive

Various helper functions for creating simple interactive systems.

These are mostly intended for helping with teaching, in that they will allow
the easy creation of interactive programs without needing to teach IO
or Effects first, but they also capture some common patterns of interactive
programming.

disableBuffering : IO ()

  Disables buffering in both stdin and stdout:
  so that output is written immediately (never stored in the buffer)
  and the next input item is read and returned

  this is useful to circumvent problems with IO on some Windows systems
  where stdout output right before a prompt is only shown after
  the input-line from stdin is produced

getArgs : IO (List String)

  Get the command-line arguments that the program was called with.

getChar : IO Char

  Read a single character from stdin

getLine : IO String

  Read one line of input from stdin, without the trailing newline

getLine' : IO' ffi String

  Read one line of input from stdin, without the trailing newline, for any FFI
  descriptor

print : Show ty => ty -> IO ()

  Output something showable to stdout, without a trailing newline

print' : Show ty => ty -> IO' ffi ()

  Output something showable to stdout, without a trailing newline, for any FFI
  descriptor

printLn : Show ty => ty -> IO ()

  Output something showable to stdout, with a trailing newline

printLn' : Show ty => ty -> IO' ffi ()

  Output something showable to stdout, with a trailing newline, for any FFI
  descriptor

processHandle : File -> (state : a) -> (onRead : a -> String -> (String, a)) -> (onEOF : a -> String) -> IO ()

  Process input from an open file handle, while maintaining a state.

  state

    the input state

  onRead

    the function to run on reading a line, returning a String to
    output and a new state

  onEOF

    the function to run on reaching end of file, returning a String
    to output

processStdin : (state : a) -> (onRead : a -> String -> (String, a)) -> (onEOI : a -> String) -> IO ()

  Process input from the standard input stream, while maintaining a state.

  state

    the input state

  onRead

    the function to run on reading a line, returning a String to
    output and a new state

  onEOI

    the function to run on reaching end of input, returning a String
    to output

putChar : Char -> IO ()

  Write a single character to stdout

putCharLn : Char -> IO ()

  Write a single character to stdout, with a trailing newline

putStr : String -> IO ()

  Output a string to stdout without a trailing newline

putStr' : String -> IO' ffi ()

  Output a string to stdout without a trailing newline, for any FFI
  descriptor

putStrLn : String -> IO ()

  Output a string to stdout with a trailing newline

putStrLn' : String -> IO' ffi ()

  Output a string to stdout with a trailing newline, for any FFI
  descriptor

repl : (prompt : String) -> (onInput : String -> String) -> IO ()

  A basic read-eval-print loop

  prompt

    the prompt to show

  onInput

    the function to run on reading input, returning a String to
    output

replWith : (state : a) -> (prompt : String) -> (onInput : a -> String -> Maybe (String, a)) -> IO ()

  A basic read-eval-print loop, maintaining a state

  state

    the input state

  prompt

    the prompt to show

  onInput

    the function to run on reading input, returning a String to
    output and a new state. Returns Nothing if the repl should exit