Module
Node.ReadLine.Aff
- Package
- purescript-node-readline-aff
- Repository
- ChrisPenner/purescript-node-readline-aff
This module provides an interface in Aff to Node.ReadLine
Example usage:
import Node.ReadLine (close) as RL
import Node.ReadLine.Aff (question, setPrompt, prompt, READLINE, createConsoleInterface, noCompletion)
main :: forall e. Eff (console :: CONSOLE, readline :: READLINE, exception :: EXCEPTION | e) Unit
main = do
interface <- createConsoleInterface noCompletion
runAff_ (either
(\err -> showError err *> RL.close interface)
(const $ RL.close interface))
(loop interface)
where
showError err = error (show err)
loop interface = do
setPrompt "$ " interface
dog <- question "What's your dog's name?\n" interface
liftEff <<< log $ ("Can I pet " <> dog <> "?")
str <- prompt interface
case uncons str of
Just {head: 'y'} -> liftEff $ log "Thanks!"
_ -> (liftEff $ log "C'mon! Be a sport about it!") *> loop interface
#close Source
close :: forall m. MonadEffect m => Interface -> m Unit
Close the specified Interface. This should upon error, or when you're done reading input.
#setPrompt Source
setPrompt :: forall m. MonadEffect m => String -> Interface -> m Unit
Set the prompt, this is displayed for future prompt
calls.
Re-exports from Node.ReadLine
#InterfaceOptions Source
data InterfaceOptions :: Type
Options passed to readline
's createInterface
#noCompletion Source
noCompletion :: Completer
A completion function which offers no completions.
#createInterface Source
createInterface :: forall r. Readable r -> Options InterfaceOptions -> Effect Interface
Builds an interface with the specified options.
- Modules
- Node.
ReadLine. Aff