Skip to content

Instantly share code, notes, and snippets.

@spl
Last active December 26, 2015 11:29
Show Gist options
  • Save spl/7144531 to your computer and use it in GitHub Desktop.
Save spl/7144531 to your computer and use it in GitHub Desktop.
Test case for cabal sandbox+repl bug with Ctrl-C
name: ib
version: 0.0.0.0
author: Sean Leather
build-type: Simple
cabal-version: >= 1.18
executable ib
main-is: Main.hs
build-depends: base == 4.6.*,
haskeline == 0.7.*
default-language: Haskell2010
module Main where
import System.Console.Haskeline
import System.Environment
import Control.Exception (AsyncException(..))
{--
Testing the line-input functions and their interaction with ctrl-c signals.
Usage:
./Test (line input)
./Test chars (character input)
./Test password (no masking characters)
./Test password \*
./Test initial (use initial text in the prompt)
--}
mySettings :: Settings IO
mySettings = defaultSettings {historyFile = Just "myhist"}
main :: IO ()
main = do
args <- getArgs
let inputFunc = case args of
["chars"] -> fmap (fmap (\c -> [c])) . getInputChar
["password"] -> getPassword Nothing
["password", [c]] -> getPassword (Just c)
["initial"] -> flip getInputLineWithInitial ("left ", "right")
_ -> getInputLine
runInputT mySettings $ withInterrupt $ loop inputFunc 0
where
loop inputFunc n = do
minput <- handle (\Interrupt -> return (Just "Caught interrupted"))
$ inputFunc (show n ++ ":")
case minput of
Nothing -> return ()
Just "quit" -> return ()
Just "q" -> return ()
Just s -> do
outputStrLn ("line " ++ show n ++ ":" ++ s)
loop inputFunc (n+1)
import Distribution.Simple
main = defaultMain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment