summaryrefslogtreecommitdiffhomepage
path: root/Plugins/StdinReader.hs
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2007-11-08 00:10:28 +0100
committerSpencer Janssen <sjanssen@cse.unl.edu>2007-11-08 00:10:28 +0100
commitfc24dc1874dcf7c9e66e21502a58b40cbe627c85 (patch)
treee3096060f8dd59aac176b38ea57b42fe0441165b /Plugins/StdinReader.hs
parent556df4664693a643bf5304f13474f80cde5a53cc (diff)
downloadxmobar-fc24dc1874dcf7c9e66e21502a58b40cbe627c85.tar.gz
xmobar-fc24dc1874dcf7c9e66e21502a58b40cbe627c85.tar.bz2
StdinReader: exit when stdin has been closed
darcs-hash:20071107231028-a5988-6787dafbed6f6c81f52989710a326e40273c2b45.gz
Diffstat (limited to 'Plugins/StdinReader.hs')
-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