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.

#prompt Source

prompt :: forall m. MonadAff m => Interface -> m String

Read a single line from input using the current prompt.

#question Source

question :: forall m. MonadAff m => String -> Interface -> m String

Writes a query to the output and returns the response

#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

#Interface Source

data Interface :: Type

A handle to a console interface.

A handle can be created with the createInterface function.

#Completer Source

type Completer = String -> Effect { 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.

#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.

#createConsoleInterface Source

createConsoleInterface :: Completer -> Effect Interface

Create an interface with the specified completion function.