summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Plugins/StdinReader.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/Plugins/StdinReader.hs b/Plugins/StdinReader.hs
index 7ad2b41..d7ec676 100644
--- a/Plugins/StdinReader.hs
+++ b/Plugins/StdinReader.hs
@@ -3,7 +3,7 @@
-- Module : Plugins.StdinReader
-- Copyright : (c) Andrea Rossato
-- License : BSD-style (see LICENSE)
---
+--
-- Maintainer : Andrea Rossato <andrea.rossato@unibz.it>
-- Stability : unstable
-- Portability : unportable
@@ -14,13 +14,20 @@
module Plugins.StdinReader where
+import Prelude hiding (catch)
+import System.Posix.Process
+import System.Exit
import System.IO
+import Control.Exception (catch)
import Plugins
data StdinReader = StdinReader
deriving (Read, Show)
-instance Exec StdinReader where
+instance Exec StdinReader where
start StdinReader cb = do
- forever (hGetLine stdin >>= cb)
- where forever a = a >> forever a
+ cb =<< catch (hGetLine stdin) (\e -> do hPrint stderr e; return "")
+ eof <- hIsEOF stdin
+ if eof
+ then exitImmediately ExitSuccess
+ else start StdinReader cb