{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses, TypeFamilies #-}
module Streaming.Process.Lifted
(
withStreamingProcess
, withStreamingCommand
, streamInput
, streamInputCommand
, withStreamingOutput
, withStreamingOutputCommand
, StreamProcess(..)
, switchOutputs
, WithStream(WithStream)
, WithStream'
, withStream
, SupplyStream(SupplyStream)
, supplyStream
, withStreamProcess
, withStreamCommand
, withProcessHandles
, processInput
, withProcessOutput
, StdOutErr
, withStreamOutputs
, module Data.Streaming.Process
, concurrently
) where
import Streaming.Process (StdOutErr, StreamProcess(..),
SupplyStream(SupplyStream),
WithStream(WithStream), WithStream',
switchOutputs)
import qualified Streaming.Process as SP
import Data.ByteString.Streaming (ByteString)
import Streaming.With.Lifted (Withable(..))
import Control.Concurrent.Async.Lifted (concurrently)
import Control.Monad.Base (MonadBase)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Streaming.Process
import System.Process (shell)
withStreamingProcess :: ( Withable w, MonadBaseControl IO (WithMonad w)
, MonadBase IO n)
=> CreateProcess -> ByteString (WithMonad w) v
-> w (StdOutErr n ())
withStreamingProcess cp inp = liftWith (SP.withStreamingProcess cp inp)
withStreamingCommand :: ( Withable w, MonadBaseControl IO (WithMonad w)
, MonadBase IO n)
=> String -> ByteString (WithMonad w) v
-> w (StdOutErr n ())
withStreamingCommand = withStreamingProcess . shell
streamInput :: (Withable w) => CreateProcess
-> ByteString (WithMonad w) r -> w r
streamInput cp inp = liftAction (SP.streamInput cp inp)
streamInputCommand :: (Withable w) => String
-> ByteString (WithMonad w) r -> w r
streamInputCommand = streamInput . shell
withStreamingOutput :: (Withable w, MonadIO n)
=> CreateProcess
-> w (ByteString n ())
withStreamingOutput cp = liftWith (SP.withStreamingOutput cp)
withStreamingOutputCommand :: (Withable w, MonadIO n)
=> String
-> w (ByteString n ())
withStreamingOutputCommand = withStreamingOutput . shell
withProcessHandles :: (Withable w, m ~ WithMonad w, MonadBaseControl IO m, MonadBase IO n)
=> ByteString m v
-> StreamProcess (SupplyStream m)
(WithStream' m)
(WithStream' m)
-> w (StdOutErr n ())
withProcessHandles inp sp = liftWith (SP.withProcessHandles inp sp)
processInput :: (Withable w)
=> StreamProcess (SupplyStream (WithMonad w)) ClosedStream ClosedStream
-> ByteString (WithMonad w) r -> w r
processInput sp inp = liftAction (SP.processInput sp inp)
withProcessOutput :: (Withable w, MonadIO n)
=> StreamProcess ClosedStream (WithStream n (WithMonad w)) ClosedStream
-> w (ByteString n ())
withProcessOutput sp = liftWith (SP.withProcessOutput sp)
withStreamProcess :: (InputSource stdin, OutputSink stdout, OutputSink stderr
, Withable w)
=> CreateProcess -> w (StreamProcess stdin stdout stderr)
withStreamProcess cp = liftWith (SP.withStreamProcess cp)
withStreamCommand :: (InputSource stdin, OutputSink stdout, OutputSink stderr
, Withable w)
=> String -> w (StreamProcess stdin stdout stderr)
withStreamCommand = withStreamProcess . shell
withStreamOutputs :: ( Withable w, m ~ WithMonad w, MonadBaseControl IO m
, MonadBase IO n)
=> StreamProcess stdin (WithStream' m) (WithStream' m)
-> w (StdOutErr n ())
withStreamOutputs sp = liftWith (SP.withStreamOutputs sp)
supplyStream :: (Withable w) => SupplyStream (WithMonad w)
-> ByteString (WithMonad w) r -> w r
supplyStream ss inp = liftAction (SP.supplyStream ss inp)
withStream :: (Withable w) => WithStream n (WithMonad w) -> w (ByteString n ())
withStream ws = liftWith (SP.withStream ws)