    {-# LANGUAGE CPP, MultiParamTypeClasses #-}
    {-# OPTIONS_GHC -fno-warn-orphans #-}
    module System.Process.Text.Builder where

    #if !MIN_VERSION_base(4,8,0)
    import Control.Applicative ((<$>))
    #endif
    import Control.DeepSeq (force)
    import qualified Control.Exception as C (evaluate)
    import Data.ListLike.IO (hGetContents)
    import Data.Text.Lazy (toChunks)
    import Data.Text.Lazy.Builder (Builder, fromText)
    import Prelude hiding (null)
    import System.Process
    import System.Process.Common
    import System.Exit (ExitCode)

    -- | Like 'System.Process.readProcessWithExitCode', but using 'Text'
    instance ListLikeProcessIO Builder Char where
        forceOutput :: Builder -> IO Builder
    forceOutput = Builder -> IO Builder
    forall a. a -> IO a
    C.evaluate (Builder -> IO Builder)
    -> (Builder -> Builder) -> Builder -> IO Builder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Builder -> Builder
    forall a. NFData a => a -> a
    force
        readChunks :: Handle -> IO [Builder]
    readChunks Handle
    h = ((Text -> Builder) -> [Text] -> [Builder]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Builder
    fromText ([Text] -> [Builder]) -> (Text -> [Text]) -> Text -> [Builder]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> [Text]
    toChunks) (Text -> [Builder]) -> IO Text -> IO [Builder]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Handle -> IO Text
    forall full item. ListLikeIO full item => Handle -> IO full
    hGetContents Handle
    h

    -- | Specialized version for backwards compatibility.
    readProcessWithExitCode
        :: FilePath                        -- ^ command to run
        -> [String]                        -- ^ any arguments
        -> Builder                         -- ^ standard input
        -> IO (ExitCode, Builder, Builder) -- ^ exitcode, stdout, stderr
    readProcessWithExitCode :: FilePath
    -> [FilePath] -> Builder -> IO (ExitCode, Builder, Builder)
    readProcessWithExitCode = FilePath
    -> [FilePath] -> Builder -> IO (ExitCode, Builder, Builder)
    forall text char.
    ListLikeProcessIO text char =>
    FilePath -> [FilePath] -> text -> IO (ExitCode, text, text)
    System.Process.Common.readProcessWithExitCode

    readCreateProcessWithExitCode
        :: CreateProcess                   -- ^ command and arguments to run
        -> Builder                         -- ^ standard input
        -> IO (ExitCode, Builder, Builder) -- ^ exitcode, stdout, stderr
    readCreateProcessWithExitCode :: CreateProcess -> Builder -> IO (ExitCode, Builder, Builder)
    readCreateProcessWithExitCode = CreateProcess -> Builder -> IO (ExitCode, Builder, Builder)
    forall maker text char.
    (ProcessMaker maker, ListLikeProcessIO text char) =>
    maker -> text -> IO (ExitCode, text, text)
    System.Process.Common.readCreateProcessWithExitCode