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

Safe Haskell | None
Language | Haskell98

System.Console.Haskeline.IO

Description

This module provides a stateful, IO-based interface to Haskeline, which may be easier to integrate into some existing programs or libraries.

It is strongly recommended to use the safer, monadic API of System.Console.Haskeline, if possible, rather than the explicit state management functions of this module.

The equivalent REPL example is:

    import System.Console.Haskeline
    import System.Console.Haskeline.IO
    import Control.Concurrent

    main = bracketOnError (initializeInput defaultSettings)
                cancelInput -- This will only be called if an exception such
                                -- as a SigINT is received.
                (\hd -> loop hd >> closeInput hd)
        where
            loop :: InputState -> IO ()
            loop hd = do
                minput <- queryInput hd (getInputLine "% ")
                case minput of
                    Nothing -> return ()
                    Just "quit" -> return ()
                    Just input -> do queryInput hd $ outputStrLn
                                        $ "Input was: " ++ input
                                     loop hd

Synopsis

- data InputState
- initializeInput :: Settings IO -> IO InputState
- closeInput :: InputState -> IO ()
- cancelInput :: InputState -> IO ()
- queryInput :: InputState -> InputT IO a -> IO a

# Documentation

data InputState

initializeInput :: Settings IO -> IO InputState

Initialize a session of line-oriented user interaction.

closeInput :: InputState -> IO ()

Finish and clean up the line-oriented user interaction session. Blocks on an existing call to `queryInput`.

cancelInput :: InputState -> IO ()

Cancel and clean up the user interaction session. Does not block on an existing call to `queryInput`.

queryInput :: InputState -> InputT IO a -> IO a

Run one action (for example, `getInputLine`) as part of a session of user interaction.

For example, multiple calls to `queryInput` using the same `InputState` will share the same input history. In constrast, multiple calls to `runInputT` will use distinct histories unless they share the same history file.

This function should not be called on a closed or cancelled `InputState`.