diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Main.hs | 23 |
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 () |
