{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
module System.Process.Lens.StdStream
(
_Inherit
, _UseHandle
, _CreatePipe
, _NoStream
, IsInherit(..)
, IsUseHandle(..)
, IsCreatePipe(..)
, IsNoStream(..)
, usehandleOf
) where
import Control.Lens
import System.IO (Handle)
import System.Process
_Inherit :: Prism' StdStream StdStream
_Inherit = prism' (const Inherit) $ \s -> case s of
Inherit -> Just Inherit
_ -> Nothing
_UseHandle :: Prism' StdStream Handle
_UseHandle = prism' UseHandle $ \s -> case s of
UseHandle t -> Just t
_ -> Nothing
_CreatePipe :: Prism' StdStream StdStream
_CreatePipe = prism' (const CreatePipe) $ \s -> case s of
CreatePipe -> Just CreatePipe
_ -> Nothing
_NoStream :: Prism' StdStream StdStream
_NoStream = prism' (const NoStream) $ \s -> case s of
NoStream -> Just NoStream
_ -> Nothing
class IsInherit a where
_Inherits :: Prism' a StdStream
{-# MINIMAL _Inherits #-}
instance IsInherit StdStream where
_Inherits = _Inherit
class IsUseHandle a where
_UsesHandle :: Prism' a Handle
{-# MINIMAL _UsesHandle #-}
instance IsUseHandle StdStream where
_UsesHandle = _UseHandle
class IsCreatePipe a where
_CreatesPipe :: Prism' a StdStream
{-# MINIMAL _CreatesPipe #-}
instance IsCreatePipe StdStream where
_CreatesPipe = _CreatePipe
class IsNoStream a where
_NoStreams :: Prism' a StdStream
{-# MINIMAL _NoStreams #-}
instance IsNoStream StdStream where
_NoStreams = _NoStream
usehandleOf :: IsUseHandle a => Handle -> a
usehandleOf h = _UsesHandle # h