This module provides a wrapper around Node.Readline providing a cleaner interface when prompting for input.

The provided combinators require MonadAff (readline :: READLINE | eff) m => MonadAsk Interface m as a constraint. So long as this is filled you can use them wherever you like.

Running your linereader program looks something like this: runAff_ resultHandler $ runLineReader Nothing myLineReaderProgram

This specializes the monad stack to ReaderT Interface (Aff (LineReaderEff e)) a. then runs it into Aff.

Example usage:

main :: forall e. Eff (console :: CONSOLE, readline :: READLINE, exception :: EXCEPTION | e) Unit
main = do
  interface <- createConsoleInterface noCompletion
  runAff_ (either (error <<< show) log) (runReaderT loop interface)
    loop = do
      setPrompt "$ "
      dog <- question "What's your dog's name?\n"
      liftEff <<< log $ "Can I pet " <> dog <> "?"
      str <- readLine
      case uncons str of
        Just {head: 'y'} -> liftEff $ log "Thanks!"
        _ -> liftEff $ log "C'mon! Be a sport about it!"

#runLineReader Source

runLineReader :: forall e a r. Maybe (Tuple (Readable r (LineReaderEff e)) (Options InterfaceOptions)) -> LineReaderM e a -> Aff (LineReaderEff e) a

Run a line reader program. You can pass your own options and readable stream or pass Nothing to use the node console.

#readLine Source

readLine :: forall m eff. MonadAff (readline :: READLINE | eff) m => MonadAsk Interface m => m String

Read a single line from input.

#question Source

question :: forall m e. MonadAff (console :: CONSOLE, readline :: READLINE | e) m => MonadAsk Interface m => String -> m String

Prompt for input, then read a line

Re-exports from Node.ReadLine.Aff


data READLINE :: Effect

The effect of interacting with a stream via an Interface

#InterfaceOptions Source

data InterfaceOptions

Options passed to readline's createInterface

#Completer Source

type Completer eff = String -> Eff eff { completions :: Array String, matched :: String }

A function which performs tab completion.

This function takes the partial command as input, and returns a collection of completions, as well as the matched portion of the input string.

#output Source

output :: forall eff w. Option InterfaceOptions (Writable w eff)

#noCompletion Source

noCompletion :: forall eff. Completer eff

A completion function which offers no completions.

#createInterface Source

createInterface :: forall eff r. Readable r (readline :: READLINE | eff) -> Options InterfaceOptions -> Eff (readline :: READLINE | eff) Interface

Builds an interface with the specified options.

#createConsoleInterface Source

createConsoleInterface :: forall eff. Completer (console :: CONSOLE, exception :: EXCEPTION, readline :: READLINE | eff) -> Eff (console :: CONSOLE, exception :: EXCEPTION, readline :: READLINE | eff) Interface

Create an interface with the specified completion function.

#completer Source