Skip to content

Commit

Permalink
Refactor terminal and signal support in preparation for Windows UI
Browse files Browse the repository at this point in the history
  • Loading branch information
elopez committed Apr 29, 2024
1 parent 0b02341 commit 26cda5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/Echidna/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Graphics.Vty.CrossPlatform (mkVty)
import Graphics.Vty.Input.Events
import Graphics.Vty (Event(..), Key(..), Modifier(..))
import Graphics.Vty qualified as Vty
import System.Posix
import System.Console.ANSI (hSupportsANSI)
import System.Signal
import Echidna.UI.Widgets
#endif

Expand Down Expand Up @@ -164,12 +165,12 @@ ui vm world dict initialCorpus = do
NonInteractive outputFormat -> do
serverStopVar <- newEmptyMVar
#ifdef INTERACTIVE_UI
-- Handles ctrl-c, TODO: this doesn't work on Windows
-- Handles ctrl-c
liftIO $ forM_ [sigINT, sigTERM] $ \sig ->
let handler = Catch $ do
let handler = \_ -> do
stopWorkers workers
void $ tryPutMVar serverStopVar ()
in installHandler sig handler Nothing
in installHandler sig handler
#endif
let forwardEvent = putStrLn . ppLogLine
uiEventsForwarderStopVar <- spawnListener forwardEvent
Expand Down Expand Up @@ -337,7 +338,7 @@ monitor = do
isTerminal :: IO Bool
isTerminal =
#ifdef INTERACTIVE_UI
(&&) <$> queryTerminal (Fd 0) <*> queryTerminal (Fd 1)
hSupportsANSI stdout
#else
pure False
#endif
Expand Down
3 changes: 2 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ library:
- condition: "!os(windows)"
cpp-options: -DINTERACTIVE_UI
dependencies:
- ansi-terminal
- brick
- unix
- signal
- vty
- vty-crossplatform

Expand Down

0 comments on commit 26cda5d

Please sign in to comment.