diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-11-02 20:10:00 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-11-02 20:10:00 +0100 |
commit | 497ea94f804b59c4c9c8b7f988fa7df9fcd3848f (patch) | |
tree | bfdc823209178894dd752213a581dd56c64d3384 /src | |
parent | c006be894348c1302f99698d18d0e4d76bac160b (diff) |
Flush stdout more
Diffstat (limited to 'src')
-rw-r--r-- | src/Ghci.hs | 9 |
1 files changed, 7 insertions, 2 deletions
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 "<timeout>") @@ -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 |