summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohn Goerzen <jgoerzen@complete.org>2008-09-16 07:20:25 +0200
committerJohn Goerzen <jgoerzen@complete.org>2008-09-16 07:20:25 +0200
commit455b75246e1af3c71f21dc3ba7fa4030f9346606 (patch)
tree831533a97de0f4e2bee32b86b847250d9ac92fc3
parent3112cc6f58bc1a6d2cd262bfc3cfb25ac988a281 (diff)
downloadxmobar-455b75246e1af3c71f21dc3ba7fa4030f9346606.tar.gz
xmobar-455b75246e1af3c71f21dc3ba7fa4030f9346606.tar.bz2
Added CommandReader
darcs-hash:20080916052025-c2a52-b56fb3901980591a17383a9267166cc3c9d34185.gz
-rw-r--r--Config.hs3
-rw-r--r--Plugins/CommandReader.hs31
2 files changed, 33 insertions, 1 deletions
diff --git a/Config.hs b/Config.hs
index f55f35d..8f6b687 100644
--- a/Config.hs
+++ b/Config.hs
@@ -28,6 +28,7 @@ import {-# SOURCE #-} Runnable
import Plugins.Monitors
import Plugins.Date
import Plugins.PipeReader
+import Plugins.CommandReader
import Plugins.StdinReader
#ifdef INOTIFY
@@ -86,7 +87,7 @@ infixr :*:
-- the 'Runnable.Runnable' Read instance. To install a plugin just add
-- the plugin's type to the list of types (separated by ':*:') appearing in
-- this function's type signature.
-runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: StdinReader :*:
+runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader :*: StdinReader :*:
#ifdef INOTIFY
Mail :*:
#endif
diff --git a/Plugins/CommandReader.hs b/Plugins/CommandReader.hs
new file mode 100644
index 0000000..b084aba
--- /dev/null
+++ b/Plugins/CommandReader.hs
@@ -0,0 +1,31 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Plugins.CommandReader
+-- Copyright : (c) John Goerzen
+-- License : BSD-style (see LICENSE)
+--
+-- Maintainer : Andrea Rossato <andrea.rossato@unibz.it>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A plugin for reading from external commands
+-- note: stderr is lost here
+--
+-----------------------------------------------------------------------------
+
+module Plugins.CommandReader where
+
+import System.IO
+import Plugins
+
+data CommandReader = CommandReader String String
+ deriving (Read, Show)
+
+instance Exec CommandReader where
+ alias (CommandReader _ a) = a
+ start (CommandReader p _) cb = do
+ (hstdin, hstdout, hstderr) <- runInteractiveCommand p
+ hClose hstdin
+ hClose hstderr
+ forever (hGetLineSafe hstdout >>= cb)
+ where forever a = a >> forever a