packages feed

haskeline-0.3: examples/Test.hs

module Main where

import System.Console.Haskeline

mySettings :: Settings IO
mySettings = defaultSettings {historyFile = Just "myhist",
                        handleSigINT = True}

main :: IO ()
main = runInputT mySettings (loop 0)
    where
        loop :: Int -> InputT IO ()
        loop n = do
            minput <-  handleInterrupt (return (Just "Caught interrupted"))
                        (getInputLine (show n ++ ":"))
            case minput of
                Nothing -> return ()
                Just "quit" -> return ()
                Just s -> do
                            outputStrLn ("line " ++ show n ++ ":" ++ s)
                            loop (n+1)