{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
module System.Process.Lens.StdStream
(
_Inherit
, _UseHandle
, _CreatePipe
, _NoStream
, AsInherit(..)
, AsUseHandle(..)
, AsCreatePipe(..)
, AsNoStream(..)
, usehandleOf
, inheriting
, piping
, handling
, nostreaming
) where
import Control.Lens
import System.IO (Handle)
import System.Process
_Inherit :: Prism' StdStream ()
_Inherit :: p () (f ()) -> p StdStream (f StdStream)
_Inherit = (() -> StdStream)
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> () -> StdStream
forall a b. a -> b -> a
const StdStream
Inherit) ((StdStream -> Maybe ()) -> Prism StdStream StdStream () ())
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall a b. (a -> b) -> a -> b
$ \case
StdStream
Inherit -> () -> Maybe ()
forall a. a -> Maybe a
Just ()
StdStream
_ -> Maybe ()
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)
-> Prism StdStream StdStream Handle Handle)
-> (StdStream -> Maybe Handle)
-> Prism StdStream StdStream Handle Handle
forall a b. (a -> b) -> a -> b
$ \case
UseHandle Handle
t -> Handle -> Maybe Handle
forall a. a -> Maybe a
Just Handle
t
StdStream
_ -> Maybe Handle
forall a. Maybe a
Nothing
_CreatePipe :: Prism' StdStream ()
_CreatePipe :: p () (f ()) -> p StdStream (f StdStream)
_CreatePipe = (() -> StdStream)
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> () -> StdStream
forall a b. a -> b -> a
const StdStream
CreatePipe) ((StdStream -> Maybe ()) -> Prism StdStream StdStream () ())
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall a b. (a -> b) -> a -> b
$ \case
StdStream
CreatePipe -> () -> Maybe ()
forall a. a -> Maybe a
Just ()
StdStream
_ -> Maybe ()
forall a. Maybe a
Nothing
_NoStream :: Prism' StdStream ()
_NoStream :: p () (f ()) -> p StdStream (f StdStream)
_NoStream = (() -> StdStream)
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (StdStream -> () -> StdStream
forall a b. a -> b -> a
const StdStream
NoStream) ((StdStream -> Maybe ()) -> Prism StdStream StdStream () ())
-> (StdStream -> Maybe ()) -> Prism StdStream StdStream () ()
forall a b. (a -> b) -> a -> b
$ \case
StdStream
NoStream -> () -> Maybe ()
forall a. a -> Maybe a
Just ()
StdStream
_ -> Maybe ()
forall a. Maybe a
Nothing
class AsInherit a where
_Inherits :: Prism' a ()
{-# MINIMAL _Inherits #-}
instance AsInherit StdStream where
_Inherits :: p () (f ()) -> p StdStream (f StdStream)
_Inherits = p () (f ()) -> p StdStream (f StdStream)
Prism StdStream StdStream () ()
_Inherit
{-# inline _Inherits #-}
class AsUseHandle a where
_UsesHandle :: Prism' a Handle
{-# MINIMAL _UsesHandle #-}
instance AsUseHandle 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
{-# inline _UsesHandle #-}
class AsCreatePipe a where
_CreatesPipe :: Prism' a ()
{-# MINIMAL _CreatesPipe #-}
instance AsCreatePipe StdStream where
_CreatesPipe :: p () (f ()) -> p StdStream (f StdStream)
_CreatesPipe = p () (f ()) -> p StdStream (f StdStream)
Prism StdStream StdStream () ()
_CreatePipe
{-# inline _CreatesPipe #-}
class AsNoStream a where
_NoStreams :: Prism' a ()
{-# MINIMAL _NoStreams #-}
instance AsNoStream StdStream where
_NoStreams :: p () (f ()) -> p StdStream (f StdStream)
_NoStreams = p () (f ()) -> p StdStream (f StdStream)
Prism StdStream StdStream () ()
_NoStream
{-# inline _NoStreams #-}
usehandleOf :: AsUseHandle 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. AsUseHandle a => Prism' a Handle
_UsesHandle
{-# inline usehandleOf #-}
inheriting :: Lens' a StdStream -> a -> a
inheriting :: Lens' a StdStream -> a -> a
inheriting 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
{-# inline inheriting #-}
piping :: Lens' a StdStream -> a -> a
piping :: Lens' a StdStream -> a -> a
piping 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
{-# inline piping #-}
handling :: Lens' a StdStream -> Handle -> a -> a
handling :: Lens' a StdStream -> Handle -> a -> a
handling 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)
{-# inline handling #-}
nostreaming :: Lens' a StdStream -> a -> a
nostreaming :: Lens' a StdStream -> a -> a
nostreaming 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
{-# inline nostreaming #-}