Commit e4efc1a2 authored by simonmar's avatar simonmar
Browse files

[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
parent c69886a1
...@@ -32,10 +32,12 @@ import System.Posix.Signals ...@@ -32,10 +32,12 @@ import System.Posix.Signals
# else # else
import Posix ( Handler(Catch), installHandler, sigINT, sigQUIT ) import Posix ( Handler(Catch), installHandler, sigINT, sigQUIT )
# endif /* GHC > 504 */ # endif /* GHC > 504 */
import CONCURRENT ( myThreadId )
#endif /* mingw32_HOST_OS */ #endif /* mingw32_HOST_OS */
#if defined(mingw32_HOST_OS) && __GLASGOW_HASKELL__ >= 603
import GHC.ConsoleHandler
#endif
# if __GLASGOW_HASKELL__ < 500 # if __GLASGOW_HASKELL__ < 500
import EXCEPTION ( raiseInThread ) import EXCEPTION ( raiseInThread )
# else # else
...@@ -46,6 +48,7 @@ import EXCEPTION ( throwTo ) ...@@ -46,6 +48,7 @@ import EXCEPTION ( throwTo )
import EXCEPTION ( catchJust, tryJust, ioErrors ) import EXCEPTION ( catchJust, tryJust, ioErrors )
#endif #endif
import CONCURRENT ( myThreadId )
import DYNAMIC import DYNAMIC
import qualified EXCEPTION as Exception import qualified EXCEPTION as Exception
import TRACE ( trace ) import TRACE ( trace )
...@@ -196,12 +199,24 @@ thread. ...@@ -196,12 +199,24 @@ thread.
\begin{code} \begin{code}
installSignalHandlers :: IO () installSignalHandlers :: IO ()
installSignalHandlers = do installSignalHandlers = do
#ifndef mingw32_HOST_OS
main_thread <- myThreadId main_thread <- myThreadId
let sig_handler = Catch (throwTo main_thread let
(Exception.DynException (toDyn Interrupted))) interrupt_exn = Exception.DynException (toDyn Interrupted)
installHandler sigQUIT sig_handler Nothing interrupt = throwTo main_thread interrupt_exn
installHandler sigINT sig_handler Nothing --
#endif #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 () return ()
#else
-- nothing
#endif
\end{code} \end{code}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment