From 976312375bbedd05eb822b3b0d5d044aa7d4a3ea Mon Sep 17 00:00:00 2001 From: Reto Habluetzel Date: Mon, 27 Aug 2012 21:07:54 +0200 Subject: added PipeReader2 which accepts a default --- src/Config.hs | 3 ++- src/Plugins/PipeReader2.hs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Plugins/PipeReader2.hs diff --git a/src/Config.hs b/src/Config.hs index a6ad3e2..58956af 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -28,6 +28,7 @@ import {-# SOURCE #-} Runnable import Plugins.Monitors import Plugins.Date import Plugins.PipeReader +import Plugins.PipeReader2 import Plugins.BufferedPipeReader import Plugins.CommandReader import Plugins.StdinReader @@ -120,7 +121,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 :*: BufferedPipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*: EWMH :*: Kbd :*: +runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: PipeReader2 :*: BufferedPipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*: EWMH :*: Kbd :*: #ifdef INOTIFY Mail :*: MBox :*: #endif diff --git a/src/Plugins/PipeReader2.hs b/src/Plugins/PipeReader2.hs new file mode 100644 index 0000000..511f107 --- /dev/null +++ b/src/Plugins/PipeReader2.hs @@ -0,0 +1,30 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.PipeReader2 +-- Copyright : (c) Andrea Rossato +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +-- A plugin for reading from named pipes. As opposed to PipeReader, this +-- plugin displays a default string when it starts. +-- +----------------------------------------------------------------------------- + +module Plugins.PipeReader2 where + +import System.IO +import Plugins + +data PipeReader2 = PipeReader2 String String String + deriving (Read, Show) + +instance Exec PipeReader2 where + alias (PipeReader2 _ a _) = a + start (PipeReader2 p _ def) cb = do + h <- openFile p ReadWriteMode + cb def + forever (hGetLineSafe h >>= cb) + where forever a = a >> forever a -- cgit v1.2.3