haskeline-0.2.1: A command-line interface for user input, written in Haskell.




Main functions

An example use of this library for a simple read-eval-print loop is the following.

 import System.Console.Haskeline
 import Control.Monad.Trans
 main :: IO ()
 main = runInputT defaultSettings loop
        loop :: InputT IO ()
        loop = do
            minput <- getInputLine "% "
            case minput of
                Nothing -> return ()
                Just "quit" -> return ()
                Just input -> do outputStrLn $ "Input was: " ++ input

data InputT m a Source

A monad transformer which carries all of the state and settings relevant to a line-reading application.


MonadTrans InputT 
Monad m => MonadState History (InputT m) 
Monad m => MonadReader Prefs (InputT m) 
Monad m => Monad (InputT m) 
Monad m => Functor (InputT m) 
Monad m => Applicative (InputT m) 
MonadIO m => MonadIO (InputT m) 
MonadException m => MonadException (InputT m) 
Monad m => MonadReader (RunTerm (InputCmdT m)) (InputT m) 
Monad m => MonadReader (Settings m) (InputT m) 

runInputT :: MonadException m => Settings m -> InputT m a -> m aSource

Run a line-reading application, reading user Prefs from ~/.haskeline



:: forall m . MonadException m 
=> String

The input prompt

-> InputT m (Maybe String) 

Read one line of input from the user, with a rich line-editing user interface. Returns Nothing if the user presses Ctrl-D when the input text is empty. Otherwise, it returns the input line with the final newline removed.

If stdin is not connected to a terminal (for example, piped from another process), then this function is equivalent to getLine, except that it returns Nothing if an EOF is encountered before any characters are read.

If signal handling is enabled in the Settings, then getInputLine will throw an Interrupt exception when the user presses Ctrl-C.

outputStr :: forall m. MonadIO m => String -> InputT m ()Source

Write a string to the console output. Allows cross-platform display of Unicode characters.

outputStrLn :: MonadIO m => String -> InputT m ()Source

Write a string to the console output, followed by a newline. Allows cross-platform display of Unicode characters.


data Settings m Source

Application-specific customizations to the user interface.




complete :: CompletionFunc m

Custom tab completion

historyFile :: Maybe FilePath
handleSigINT :: Bool

Throw an Interrupt exception if the user presses Ctrl-C


Monad m => MonadReader (Settings m) (InputT m) 

defaultSettings :: MonadIO m => Settings mSource

A useful default. In particular:

 defaultSettings = Settings {
           complete = completeFilename,
           historyFile = Nothing,
           handleSigINT = False

setComplete :: CompletionFunc m -> Settings m -> Settings mSource

Because complete is the only field of Settings depending on m, the expression defaultSettings {completionFunc = f} leads to a type error from being too general. This function may become unnecessary if another field depending on m is added.

Ctrl-C handling



:: MonadException m 
=> m a

Handler to run if Ctrl-C is pressed

-> m a

Computation to run

-> m a 

Catch and handle an exception of type Interrupt.