summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/PipeReader2.hs
blob: 511f107bd68ab1677040285c2d13bdd305496d40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-----------------------------------------------------------------------------
-- |
-- Module      :  Plugins.PipeReader2
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Jose A. Ortega Ruiz <jao@gnu.org>
-- 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