[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / posix / po007 / Main.hs
diff --git a/ghc/misc/examples/posix/po007/Main.hs b/ghc/misc/examples/posix/po007/Main.hs
new file mode 100644 (file)
index 0000000..d70e913
--- /dev/null
@@ -0,0 +1,31 @@
+import LibPosix
+
+main = 
+    installHandler keyboardSignal (Catch doCtrlC) Nothing >>
+    getTerminalAttributes stdInput >>= \ ta ->
+    case (controlChar ta Interrupt) of
+      Nothing -> fixMe ta
+      Just x -> continue x
+
+fixMe ta =
+    putStr "Oops...no interrupt character?\nI can fix that...\n" >>
+    setTerminalAttributes stdInput (withCC ta (Interrupt, '\ETX')) Immediately >>
+    getTerminalAttributes stdInput >>= \ ta ->
+    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 = ['^', (chr (ord x + ord '@'))]