1module Main where
2
3import System.Console.Haskeline
4import System.Environment
5
6{--
7Testing the line-input functions and their interaction with ctrl-c signals.
8
9Usage:
10./Test          (line input)
11./Test chars    (character input)
12./Test password (no masking characters)
13./Test password \*
14./Test initial  (use initial text in the prompt)
15--}
16
17mySettings :: Settings IO
18mySettings = defaultSettings {historyFile = Just "myhist"}
19
20main :: IO ()
21main = do
22        args <- getArgs
23        let inputFunc = case args of
24                ["chars"] -> fmap (fmap (\c -> [c])) . getInputChar
25                ["password"] -> getPassword Nothing
26                ["password", [c]] -> getPassword (Just c)
27                ["initial"] -> flip getInputLineWithInitial ("left ", "right")
28                _ -> getInputLine
29        runInputT mySettings $ withInterrupt $ loop inputFunc 0
30    where
31        loop :: (String -> InputT IO (Maybe String)) -> Int -> InputT IO ()
32        loop inputFunc n = do
33            minput <-  handleInterrupt (return (Just "Caught interrupted"))
34                        $ inputFunc (show n ++ ":")
35            case minput of
36                Nothing -> return ()
37                Just "quit" -> return ()
38                Just "q" -> return ()
39                Just s -> do
40                            outputStrLn ("line " ++ show n ++ ":" ++ s)
41                            loop inputFunc (n+1)
42