LineReader
- Package
- purescript-line-reader
- Repository
- ChrisPenner/purescript-line-reader
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)
where
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!"
loop
#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.
Re-exports from Node.ReadLine.Aff
#InterfaceOptions Source
data InterfaceOptions
Options passed to readline
's createInterface
#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.
- Modules
- LineReader
- LineReader.
Run