summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/libposix/posix007.hs
diff options
context:
space:
mode:
authorDavid Terei <davidterei@gmail.com>2011-07-20 11:09:03 -0700
committerDavid Terei <davidterei@gmail.com>2011-07-20 11:26:35 -0700
commit16514f272fb42af6e9c7674a9bd6c9dce369231f (patch)
treee4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/lib/libposix/posix007.hs
parentebd422aed41048476aa61dd4c520d43becd78682 (diff)
downloadhaskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/lib/libposix/posix007.hs')
-rw-r--r--testsuite/tests/lib/libposix/posix007.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/testsuite/tests/lib/libposix/posix007.hs b/testsuite/tests/lib/libposix/posix007.hs
new file mode 100644
index 0000000000..2e62820511
--- /dev/null
+++ b/testsuite/tests/lib/libposix/posix007.hs
@@ -0,0 +1,34 @@
+import Posix
+
+-- This test is an example of where something more sophisticated than runstdtest
+-- is required, as its interactive.
+
+main = do
+ installHandler keyboardSignal (Catch doCtrlC) Nothing
+ ta <- getTerminalAttributes stdInput
+ case (controlChar ta Interrupt) of
+ Nothing -> fixMe ta
+ Just x -> continue x
+
+fixMe ta = do
+ putStr "Oops...no interrupt character?\nI can fix that...\n"
+ setTerminalAttributes stdInput (withCC ta (Interrupt, '\ETX')) Immediately
+ ta <- getTerminalAttributes stdInput
+ case (controlChar ta Interrupt) of
+ Nothing -> putStr "...Then again, maybe I can't\n"
+ Just x -> continue x
+
+continue x =
+ putStr "Press '"
+ putStr (ccStr x)
+ putStr "'.\n"
+ awaitSignal Nothing
+ putStr "How did I get here?\n"
+
+doCtrlC =
+ putStr "Caught an interrupt.\n"
+
+ccStr '\DEL' = "^?"
+ccStr x
+ | x >= ' ' = [x]
+ | otherwise = ['^', (toEnum (fromEnum x + fromEnum '@'))]