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

#question Source

question :: forall m eff. MonadAff (readline :: READLINE | eff) m => String -> Interface -> m String

Writes a query to the output and returns the response

#setPrompt Source

setPrompt :: forall m eff. MonadEff (readline :: READLINE | eff) m => String -> Interface -> m Unit

Set the prompt, this is displayed for future prompt calls.

#prompt Source

prompt :: forall m eff. MonadAff (readline :: READLINE | eff) m => Interface -> m String

Read a single line from input using the current prompt.

#close Source

close :: forall m eff. MonadEff (readline :: READLINE | eff) m => Interface -> m Unit

Close the specified Interface. This should upon error, or when you're done reading input.

Re-exports from Node.ReadLine

#READLINE

data READLINE :: Effect

The effect of interacting with a stream via an Interface

#InterfaceOptions

data InterfaceOptions

Options passed to readline's createInterface

#Interface

data Interface :: Type

A handle to a console interface.

A handle can be created with the createInterface function.

#Completer

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.

#terminal

terminal :: Option InterfaceOptions Boolean

#output

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

#noCompletion

noCompletion :: forall eff. Completer eff

A completion function which offers no completions.

#historySize

historySize :: Option InterfaceOptions Int

#createInterface

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

Builds an interface with the specified options.

#createConsoleInterface

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

completer :: forall eff. Option InterfaceOptions (Completer eff)