From 497ea94f804b59c4c9c8b7f988fa7df9fcd3848f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 2 Nov 2022 20:10:00 +0100 Subject: Flush stdout more --- cabal.project | 2 ++ src/Ghci.hs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cabal.project b/cabal.project index 23c8721..58f01b5 100644 --- a/cabal.project +++ b/cabal.project @@ -1,5 +1,7 @@ packages: . +with-compiler: ghc-8.10.7 + allow-newer: irc-client:bytestring, irc-client:text, diff --git a/src/Ghci.hs b/src/Ghci.hs index f931a7b..7567133 100644 --- a/src/Ghci.hs +++ b/src/Ghci.hs @@ -23,7 +23,7 @@ import qualified Data.ByteString.Short as BSS import Data.Char (isSpace, toLower) import Data.List (nub) import Foreign (allocaBytes) -import System.IO (hFlush, hIsClosed, hGetBufSome, hPutStrLn, stderr, Handle) +import System.IO (hFlush, hIsClosed, hGetBufSome, hPutStrLn, stdout, stderr, Handle) import System.Process import System.Random (getStdRandom, uniformR) import System.Timeout (timeout) @@ -77,6 +77,7 @@ runStmtClever ghci line = | "quit" `startsWith` cmd -> do terminateGhci ghci putStrLn "ghci: restarting due to :quit" + hFlush stdout ghci' <- makeGhci return (ghci', Return "") _ -> runStmt ghci line @@ -95,6 +96,7 @@ timeouting microseconds f ghci = -- 'restarting'. timeout microseconds (f ghci) >>= \case Nothing -> do putStrLn "ghci: restarting due to timeout" + hFlush stdout terminateGhci ghci ghci' <- makeGhci return (ghci', Error "") @@ -106,12 +108,15 @@ restarting numExcRestarts f ghci = do ghci' <- if closed then do putStrLn "ghci: restarting due to closed stdin" + hFlush stdout terminateGhci ghci makeGhci else return ghci - (f ghci' >>= \x -> return (ghci', Return x)) + + fmap (\x -> (ghci', Return x)) (f ghci') `catch` (\e -> do let _ = e :: SomeException putStrLn $ "ghci: restarting due to exception: " ++ show e + hFlush stdout terminateGhci ghci' ghci'' <- makeGhci if numExcRestarts >= 1 -- cgit v1.2.3