editline-0.1: Bindings to the editline library (libedit).ContentsIndex
System.Console.Editline
Portabilitynon-portable (requires libedit)
Stabilityexperimental
Maintainerjudah.jacobson@gmail.com
Description

A Haskell binding to the editline library. For more information about that library, see http://www.thrysoee.dk/editline/.

The following example illustrates using this library to write a loop that will process input until it reaches EOF or a Ctrl-D is typed.

editlineLoop :: IO ()
 editlineLoop = do
    prog <- System.Environment.getProgName
    el <- elInit prog
    setPrompt el (return "input: ")
    setEditor el Vi
    let loop = do
         maybeLine <- elGets el
         case maybeLine of
             Nothing -> return () -- ctrl-D
             Just line -> do
                 let line' = init line -- remove trailing '\n'
                 putStrLn $ "User input: " ++ show line'
                 loop
    loop
 
Synopsis
data EditLine
elInit :: String -> IO EditLine
reset :: EditLine -> IO ()
elGets :: EditLine -> IO (Maybe String)
setPrompt :: EditLine -> IO String -> IO ()
data Editor
= Vi
| Emacs
setEditor :: EditLine -> Editor -> IO ()
Documentation
data EditLine
elInit
:: StringThe name of the calling program; used when reading the editrc file to determine which settings to use.
-> IO EditLine
Initialize the line editor.
reset :: EditLine -> IO ()
Reset the terminal and the parser. This should be called after an error which may have upset the terminal's state.
elGets :: EditLine -> IO (Maybe String)
Read a line of input from the terminal. Returns Nothing if no characters were read or if an error occured.
setPrompt :: EditLine -> IO String -> IO ()
Set a function that will determine the prompt string.
data Editor
Constructors
Vi
Emacs
setEditor :: EditLine -> Editor -> IO ()
Set the editor keymap mode.
Produced by Haddock version 0.8