haskeline-0.4: A command-line interface for user input, written in Haskell.Source codeContentsIndex
System.Console.Haskeline
Contents
Main functions
Settings
Ctrl-C handling
Description

A rich user interface for line input in command-line programs. Haskeline is Unicode-aware and runs both on POSIX-compatible systems and on Windows.

Users may customize the interface with a ~/.haskeline file; see the System.Console.Haskeline.Prefs module for more details.

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

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

If either stdin or stdout is not connected to a terminal (for example, piped from another process), Haskeline will treat it as a UTF-8-encoded file handle.

Synopsis
data InputT m a
runInputT :: MonadException m => Settings m -> InputT m a -> m a
runInputTWithPrefs :: MonadException m => Prefs -> Settings m -> InputT m a -> m a
getInputLine :: forall m. MonadException m => String -> InputT m (Maybe String)
outputStr :: MonadIO m => String -> InputT m ()
outputStrLn :: MonadIO m => String -> InputT m ()
data Settings m = Settings {
complete :: CompletionFunc m
historyFile :: Maybe FilePath
}
defaultSettings :: MonadIO m => Settings m
setComplete :: CompletionFunc m -> Settings m -> Settings m
data Interrupt = Interrupt
withInterrupt :: MonadException m => InputT m a -> InputT m a
handleInterrupt :: MonadException m => m a -> m a -> m a
module System.Console.Haskeline.Completion
module System.Console.Haskeline.Prefs
module System.Console.Haskeline.MonadException
Main functions
data InputT m a Source
A monad transformer which carries all of the state and settings relevant to a line-reading application.
show/hide Instances
MonadTrans InputT
Monad m => MonadState History (InputT m)
Monad m => MonadReader RunTerm (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 (Settings m) (InputT m)
runInputT :: MonadException m => Settings m -> InputT m a -> m aSource
Run a line-reading application, reading user Prefs from ~/.haskeline
runInputTWithPrefs :: MonadException m => Prefs -> Settings m -> InputT m a -> m aSource
getInputLineSource
:: forall m . MonadException m
=> StringThe input prompt
-> InputT m (Maybe String)

Read one line of input. The final newline (if any) is removed.

If stdin is connected to a terminal with echoing enabled, getInputLine provides a rich line-editing user interface. It returns Nothing if the user presses Ctrl-D when the input text is empty. All user interaction, including display of the input prompt, will occur on the user's output terminal (which may differ from stdout).

If stdin is not connected to a terminal, getInputLine prints the prompt to stdout and reads one line of input. It returns Nothing if an EOF is encountered before any characters are read.

outputStr :: MonadIO m => String -> InputT m ()Source
Write a string to the standard output. Allows cross-platform display of Unicode characters.
outputStrLn :: MonadIO m => String -> InputT m ()Source
Write a string to the standard output, followed by a newline. Allows cross-platform display of Unicode characters.
Settings
data Settings m Source
Application-specific customizations to the user interface.
Constructors
Settings
complete :: CompletionFunc mCustom tab completion
historyFile :: Maybe FilePath
show/hide Instances
Monad m => MonadReader (Settings m) (InputT m)
defaultSettings :: MonadIO m => Settings mSource

A useful default. In particular:

 defaultSettings = Settings {
           complete = completeFilename,
           historyFile = Nothing,
           }
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 works around that issue, and may become unnecessary if another field depending on m is added.
Ctrl-C handling

The following functions provide portable handling of Ctrl-C events.

These functions are not necessary on GHC version 6.10 or later, which processes Ctrl-C events as exceptions by default.

data Interrupt Source
Constructors
Interrupt
show/hide Instances
withInterrupt :: MonadException m => InputT m a -> InputT m aSource
If Ctrl-C is pressed during the given computation, throw an exception of type Interrupt.
handleInterruptSource
:: MonadException m
=> m aHandler to run if Ctrl-C is pressed
-> m aComputation to run
-> m a
Catch and handle an exception of type Interrupt.
module System.Console.Haskeline.Completion
module System.Console.Haskeline.Prefs
module System.Console.Haskeline.MonadException
Produced by Haddock version 2.4.2