From e4efc1a2e261ea0772943d09e61f6c44d00b4004 Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 17 Dec 2004 15:14:47 +0000 Subject: [PATCH] [project @ 2004-12-17 15:14:47 by simonmar] Support for Ctrl-C on Windows. This works fine in a cmd.exe shell, but in a Cygwin bash shell you have to press Ctrl-Break to get an interrupt. There appears to be a long thread on the cygwin mailing list back in 2002 about this, but life is probably too short to investigate further. http://www.cygwin.com/ml/cygwin/2002-01/msg00163.html --- ghc/compiler/utils/Panic.lhs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/ghc/compiler/utils/Panic.lhs b/ghc/compiler/utils/Panic.lhs index 60393b5..cb1a684 100644 --- a/ghc/compiler/utils/Panic.lhs +++ b/ghc/compiler/utils/Panic.lhs @@ -32,10 +32,12 @@ import System.Posix.Signals # else import Posix ( Handler(Catch), installHandler, sigINT, sigQUIT ) # endif /* GHC > 504 */ - -import CONCURRENT ( myThreadId ) #endif /* mingw32_HOST_OS */ +#if defined(mingw32_HOST_OS) && __GLASGOW_HASKELL__ >= 603 +import GHC.ConsoleHandler +#endif + # if __GLASGOW_HASKELL__ < 500 import EXCEPTION ( raiseInThread ) # else @@ -46,6 +48,7 @@ import EXCEPTION ( throwTo ) import EXCEPTION ( catchJust, tryJust, ioErrors ) #endif +import CONCURRENT ( myThreadId ) import DYNAMIC import qualified EXCEPTION as Exception import TRACE ( trace ) @@ -196,12 +199,24 @@ thread. \begin{code} installSignalHandlers :: IO () installSignalHandlers = do -#ifndef mingw32_HOST_OS main_thread <- myThreadId - let sig_handler = Catch (throwTo main_thread - (Exception.DynException (toDyn Interrupted))) - installHandler sigQUIT sig_handler Nothing - installHandler sigINT sig_handler Nothing -#endif + let + interrupt_exn = Exception.DynException (toDyn Interrupted) + interrupt = throwTo main_thread interrupt_exn + -- +#if !defined(mingw32_HOST_OS) + installHandler sigQUIT interrupt Nothing + installHandler sigINT interrupt Nothing + return () +#elif __GLASGOW_HASKELL__ >= 603 + -- GHC 6.3+ has support for console events on Windows + let sig_handler ControlC = interrupt + sig_handler Break = interrupt + sig_handler _ = return () + + installHandler (Catch sig_handler) return () +#else + -- nothing +#endif \end{code} -- 1.7.10.4