Last active
December 26, 2015 11:29
-
-
Save spl/7144531 to your computer and use it in GitHub Desktop.
Test case for cabal sandbox+repl bug with Ctrl-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Distribution.Simple | |
main = defaultMain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment