forked from robdockins/shellac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor ControlC handler into a separate module
use POSIX signals on *nix and GHC.ConsoleHandler on Windows darcs-hash:20060607200418-f399b-a65403ba312dba1f9cd14069a95654fe46ea58be
- Loading branch information
1 parent
cd0dd30
commit 00c1d6c
Showing
3 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module System.Console.Shell.ConsoleHandler | ||
( withControlCHandler | ||
) where | ||
|
||
import qualified Control.Exception as Ex | ||
|
||
#ifndef mingw32_HOST_OS | ||
|
||
import qualified System.Posix.Signals as PS | ||
|
||
withControlCHandler :: IO () -> IO a -> IO a | ||
withControlCHandler hdl m = | ||
Ex.bracket | ||
(PS.installHandler PS.keyboardSignal (PS.Catch hdl) Nothing) | ||
(\oldh -> PS.installHandler PS.keyboardSignal oldh Nothing) | ||
(\_ -> m) | ||
|
||
#else | ||
|
||
import qualified GHC.ConsoleHandler as CH | ||
|
||
|
||
handleCtrlC :: IO () -> CH.Handler | ||
handleCtrlC m = CH.Catch $ \ev -> | ||
case ev of | ||
CH.ControlC -> m | ||
_ -> return () | ||
|
||
|
||
withControlCHandler :: IO () -> IO a -> IO a | ||
withControlCHandler hdl m = | ||
Ex.bracket | ||
(CH.installHandler (handleCtrlC hdl)) | ||
(\oldh -> CH.installlHandler oldh) | ||
(\_ -> m) | ||
|
||
|
||
#endif |
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