Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add windows Ctrl+C handling
  • Loading branch information
sharno committed Jun 11, 2020
1 parent 8b57038 commit 609d78c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions parser-typechecker/unison-parser-typechecker.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ executable unison
temporary,
text,
unison-core,
unison-parser-typechecker,
unix
unison-parser-typechecker
if !os(windows)
build-depends:
unix

executable prettyprintdemo
main-is: Main.hs
Expand Down
17 changes: 16 additions & 1 deletion parser-typechecker/unison/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# Language OverloadedStrings #-}
{-# Language PartialTypeSignatures #-}
{-# Language ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}

module Main where
Expand All @@ -26,7 +27,6 @@ import qualified Unison.Util.Cache as Cache
import qualified Version
import qualified Unison.Codebase.TranscriptParser as TR
import qualified System.Path as Path
import qualified System.Posix.Signals as Sig
import qualified System.FilePath as FP
import qualified System.IO.Temp as Temp
import qualified System.Exit as Exit
Expand All @@ -38,6 +38,12 @@ import qualified Data.Text as Text
import qualified Data.Configurator as Config
import Text.Megaparsec (runParser)

#if defined(mingw32_HOST_OS)
import qualified GHC.ConsoleHandler as WinSig
#else
import qualified System.Posix.Signals as Sig
#endif

usage :: String -> P.Pretty P.ColorText
usage executableStr = P.callout "🌻" $ P.lines [
P.bold "Usage instructions for the Unison Codebase Manager",
Expand Down Expand Up @@ -102,8 +108,17 @@ installSignalHandlers = do
case r of
Nothing -> return ()
Just t -> throwTo t UserInterrupt

#if defined(mingw32_HOST_OS)
let sig_handler WinSig.ControlC = interrupt
sig_handler WinSig.Break = interrupt
sig_handler _ = return ()
_ <- WinSig.installHandler (WinSig.Catch sig_handler)
#else
_ <- Sig.installHandler Sig.sigQUIT (Sig.Catch interrupt) Nothing
_ <- Sig.installHandler Sig.sigINT (Sig.Catch interrupt) Nothing
#endif

return ()

main :: IO ()
Expand Down

0 comments on commit 609d78c

Please sign in to comment.