{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
module System.Process.Lens.StdStream
(
_Inherit
, _UseHandle
, _CreatePipe
, _NoStream
, IsInherit(..)
, IsUseHandle(..)
, IsCreatePipe(..)
, IsNoStream(..)
, usehandleOf
, inheriting
, piping
, handling
, nostreaming
) where
import Control.Lens
import System.IO (Handle)
import System.Process
_Inherit :: Prism' StdStream StdStream
_Inherit :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_Inherit = (StdStream -> StdStream)
-> (StdStream -> Maybe StdStream)
-> Prism StdStream StdStream StdStream StdStream
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> StdStream -> StdStream
forall a b. a -> b -> a
const StdStream
Inherit) ((StdStream -> Maybe StdStream)
-> p StdStream (f StdStream) -> p StdStream (f StdStream))
-> (StdStream -> Maybe StdStream)
-> p StdStream (f StdStream)
-> p StdStream (f StdStream)
forall a b. (a -> b) -> a -> b
$ \s :: StdStream
s -> case StdStream
s of
Inherit -> StdStream -> Maybe StdStream
forall a. a -> Maybe a
Just StdStream
Inherit
_ -> Maybe StdStream
forall a. Maybe a
Nothing
_UseHandle :: Prism' StdStream Handle
_UseHandle :: p Handle (f Handle) -> p StdStream (f StdStream)
_UseHandle = (Handle -> StdStream)
-> (StdStream -> Maybe Handle)
-> Prism StdStream StdStream Handle Handle
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Handle -> StdStream
UseHandle ((StdStream -> Maybe Handle)
-> p Handle (f Handle) -> p StdStream (f StdStream))
-> (StdStream -> Maybe Handle)
-> p Handle (f Handle)
-> p StdStream (f StdStream)
forall a b. (a -> b) -> a -> b
$ \s :: StdStream
s -> case StdStream
s of
UseHandle t :: Handle
t -> Handle -> Maybe Handle
forall a. a -> Maybe a
Just Handle
t
_ -> Maybe Handle
forall a. Maybe a
Nothing
_CreatePipe :: Prism' StdStream StdStream
_CreatePipe :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_CreatePipe = (StdStream -> StdStream)
-> (StdStream -> Maybe StdStream)
-> Prism StdStream StdStream StdStream StdStream
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> StdStream -> StdStream
forall a b. a -> b -> a
const StdStream
CreatePipe) ((StdStream -> Maybe StdStream)
-> p StdStream (f StdStream) -> p StdStream (f StdStream))
-> (StdStream -> Maybe StdStream)
-> p StdStream (f StdStream)
-> p StdStream (f StdStream)
forall a b. (a -> b) -> a -> b
$ \s :: StdStream
s -> case StdStream
s of
CreatePipe -> StdStream -> Maybe StdStream
forall a. a -> Maybe a
Just StdStream
CreatePipe
_ -> Maybe StdStream
forall a. Maybe a
Nothing
_NoStream :: Prism' StdStream StdStream
_NoStream :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_NoStream = (StdStream -> StdStream)
-> (StdStream -> Maybe StdStream)
-> Prism StdStream StdStream StdStream StdStream
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> StdStream -> StdStream
forall a b. a -> b -> a
const StdStream
NoStream) ((StdStream -> Maybe StdStream)
-> p StdStream (f StdStream) -> p StdStream (f StdStream))
-> (StdStream -> Maybe StdStream)
-> p StdStream (f StdStream)
-> p StdStream (f StdStream)
forall a b. (a -> b) -> a -> b
$ \s :: StdStream
s -> case StdStream
s of
NoStream -> StdStream -> Maybe StdStream
forall a. a -> Maybe a
Just StdStream
NoStream
_ -> Maybe StdStream
forall a. Maybe a
Nothing
class IsInherit a where
_Inherits :: Prism' a StdStream
{-# MINIMAL _Inherits #-}
instance IsInherit StdStream where
_Inherits :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_Inherits = p StdStream (f StdStream) -> p StdStream (f StdStream)
Prism StdStream StdStream StdStream StdStream
_Inherit
class IsUseHandle a where
_UsesHandle :: Prism' a Handle
{-# MINIMAL _UsesHandle #-}
instance IsUseHandle StdStream where
_UsesHandle :: p Handle (f Handle) -> p StdStream (f StdStream)
_UsesHandle = p Handle (f Handle) -> p StdStream (f StdStream)
Prism StdStream StdStream Handle Handle
_UseHandle
class IsCreatePipe a where
_CreatesPipe :: Prism' a StdStream
{-# MINIMAL _CreatesPipe #-}
instance IsCreatePipe StdStream where
_CreatesPipe :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_CreatesPipe = p StdStream (f StdStream) -> p StdStream (f StdStream)
Prism StdStream StdStream StdStream StdStream
_CreatePipe
class IsNoStream a where
_NoStreams :: Prism' a StdStream
{-# MINIMAL _NoStreams #-}
instance IsNoStream StdStream where
_NoStreams :: p StdStream (f StdStream) -> p StdStream (f StdStream)
_NoStreams = p StdStream (f StdStream) -> p StdStream (f StdStream)
Prism StdStream StdStream StdStream StdStream
_NoStream
usehandleOf :: IsUseHandle a => Handle -> a
usehandleOf :: Handle -> a
usehandleOf = AReview a Handle -> Handle -> a
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview a Handle
forall a. IsUseHandle a => Prism' a Handle
_UsesHandle
inheriting :: Lens' a StdStream -> a -> a
inheriting :: Lens' a StdStream -> a -> a
inheriting l :: Lens' a StdStream
l = ASetter a a StdStream StdStream -> StdStream -> a -> a
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter a a StdStream StdStream
Lens' a StdStream
l StdStream
Inherit
piping :: Lens' a StdStream -> a -> a
piping :: Lens' a StdStream -> a -> a
piping l :: Lens' a StdStream
l = ASetter a a StdStream StdStream -> StdStream -> a -> a
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter a a StdStream StdStream
Lens' a StdStream
l StdStream
CreatePipe
handling :: Lens' a StdStream -> Handle -> a -> a
handling :: Lens' a StdStream -> Handle -> a -> a
handling l :: Lens' a StdStream
l = ASetter a a Handle Handle -> Handle -> a -> a
forall s t a b. ASetter s t a b -> b -> s -> t
set ((StdStream -> Identity StdStream) -> a -> Identity a
Lens' a StdStream
l ((StdStream -> Identity StdStream) -> a -> Identity a)
-> ((Handle -> Identity Handle) -> StdStream -> Identity StdStream)
-> ASetter a a Handle Handle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Handle -> Identity Handle) -> StdStream -> Identity StdStream
Prism StdStream StdStream Handle Handle
_UseHandle)
nostreaming :: Lens' a StdStream -> a -> a
nostreaming :: Lens' a StdStream -> a -> a
nostreaming l :: Lens' a StdStream
l = ASetter a a StdStream StdStream -> StdStream -> a -> a
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter a a StdStream StdStream
Lens' a StdStream
l StdStream
NoStream