Haskell Libraries
Prev | Chapter 9. The `util` package: miscellaneous utilities | Next

# 9.4. `Readline`: Command line editing

(Darren Moffat supplied the initial version of the `Readline` module.)

The `Readline` module is a straightforward interface to the GNU Readline library. As such, you will need to look at the GNU documentation (and have a `libreadline.a` file around somewhere…)

The main function you'll use is:

    readline :: String{-the prompt-} -> IO (Maybe String)

If you want to mess around with Full Readline G(l)ory, we also provide:

    type KeyCode = Char

    type CallbackFunction =
        (Int ->     -- Numeric Argument
         KeyCode -> -- KeyCode of pressed Key
         IO Int)    -- What's this?

    initialize      :: IO ()
    addHistory      :: String -> IO ()
    bindKey         :: KeyCode -> CallbackFunction -> IO ()
    addDefun        :: String  -> CallbackFunction -> Maybe KeyCode -> IO ()

    getReadlineName :: IO String
    setReadlineName :: String -> IO ()
    getLineBuffer   :: IO String
    setLineBuffer   :: String -> IO ()
    getPoint        :: IO Int
    setPoint        :: Int -> IO ()
    getEnd          :: IO Int
    setEnd          :: Int -> IO ()
    getMark         :: IO Int
    setMark         :: Int -> IO ()
    setDone         :: Bool -> IO ()
    setPendingInput :: KeyCode -> IO ()
    getPrompt       :: IO String
    getTerminalName :: IO String

    inStream        :: Handle
    outStream       :: Handle

(All those names are just Haskellised versions of what you will see in the GNU readline documentation.)

Prev | Home | Next
`QuickCheck` | Up | `Select`: Synchronous I/O multiplexing