editline-0.2.1.1: Bindings to the editline library (libedit).

Copyright(c) 2008, Judah Jacobson
LicenseBSD3
Maintainerjudah.jacobson@gmail.com
Stabilityexperimental
Portabilitynon-portable (requires libedit)
Safe HaskellNone
LanguageHaskell98

System.Console.Editline

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

Documentation

elInit Source

Arguments

:: String

The 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 () Source

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) Source

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 () Source

Set a function that will determine the prompt string.

data Editor Source

Constructors

Vi 
Emacs 

setEditor :: EditLine -> Editor -> IO () Source

Set the editor keymap mode.