aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-07-25 11:55:46 +0200
committerTom Smeding <tom@tomsmeding.com>2026-07-25 11:55:46 +0200
commit2687d558497f4b26ad66b13663d26a71bc2e1751 (patch)
treea5e08b8f0dced6d9f2c0c32cd06886e2500bd637 /src/Main.hs
parent638803c27a06c076f5f235bbf753b00738c56915 (diff)
Catch EOF exception in CLI mode
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 89e27d7..b492068 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -4,7 +4,8 @@
module Main where
import Control.Concurrent.MVar
-import Control.Exception (handle)
+import Control.Exception (handle, tryJust)
+import Control.Monad (guard)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as Char8
import qualified Data.ByteString.Lazy.Char8 as LChar8
@@ -23,6 +24,7 @@ import qualified Network.HTTP.Types.Status as N
import System.Environment (getArgs)
import System.Exit (die)
import System.IO (hFlush, stdout)
+import System.IO.Error (isEOFError)
import Ghci
import IRC
@@ -136,14 +138,17 @@ mainGHCI :: IO ()
mainGHCI = do
let loop :: Ghci -> IO ()
loop ghci = do
- line <- getLine
- (ghci', moutput) <- runStmtClever ghci parseSettingsReply line
- case moutput of
- Return output -> putStrLn $ "output = <" ++ output ++ ">"
- Ignored -> putStrLn "<ignored>"
- Error err -> putStrLn err
- Exited -> putStrLn $ "<exited>"
- loop ghci'
+ mline <- tryJust (guard . isEOFError) getLine
+ case mline of
+ Left _ -> putStrLn "<EOF received on stdin, exiting>"
+ Right line -> do
+ (ghci', moutput) <- runStmtClever ghci parseSettingsReply line
+ case moutput of
+ Return output -> putStrLn $ "output = <" ++ output ++ ">"
+ Ignored -> putStrLn "<ignored>"
+ Error err -> putStrLn err
+ Exited -> putStrLn $ "<exited>"
+ loop ghci'
makeGhci >>= loop
main :: IO ()