{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Text.Pretty.Simple
(
pPrint
, pHPrint
, pPrintString
, pHPrintString
, pPrintForceColor
, pHPrintForceColor
, pPrintStringForceColor
, pHPrintStringForceColor
, pShow
, pString
, pPrintDarkBg
, pHPrintDarkBg
, pPrintStringDarkBg
, pHPrintStringDarkBg
, pPrintForceColorDarkBg
, pHPrintForceColorDarkBg
, pPrintStringForceColorDarkBg
, pHPrintStringForceColorDarkBg
, pShowDarkBg
, pStringDarkBg
, pPrintLightBg
, pHPrintLightBg
, pPrintStringLightBg
, pHPrintStringLightBg
, pPrintForceColorLightBg
, pHPrintForceColorLightBg
, pPrintStringForceColorLightBg
, pHPrintStringForceColorLightBg
, pShowLightBg
, pStringLightBg
, pPrintNoColor
, pHPrintNoColor
, pPrintStringNoColor
, pHPrintStringNoColor
, pShowNoColor
, pStringNoColor
, pPrintOpt
, pHPrintOpt
, pPrintStringOpt
, pHPrintStringOpt
, pShowOpt
, pStringOpt
, OutputOptions(..)
, StringOutputStyle(..)
, defaultOutputOptionsDarkBg
, defaultOutputOptionsLightBg
, defaultOutputOptionsNoColor
, CheckColorTty(..)
, defaultColorOptionsDarkBg
, defaultColorOptionsLightBg
, ColorOptions(..)
, Style(..)
, Color(..)
, Intensity(..)
, colorNull
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Text.Lazy (Text)
import Prettyprinter (SimpleDocStream)
import Prettyprinter.Render.Terminal
(Color (..), Intensity(Vivid,Dull), AnsiStyle,
renderLazy, renderIO)
import System.IO (Handle, stdout, hPutStrLn)
import Text.Pretty.Simple.Internal
(ColorOptions(..), Style(..), CheckColorTty(..),
OutputOptions(..), StringOutputStyle(..),
convertStyle, colorNull,
defaultColorOptionsDarkBg, defaultColorOptionsLightBg,
defaultOutputOptionsDarkBg, defaultOutputOptionsLightBg,
defaultOutputOptionsNoColor, hCheckTTY, layoutString)
pPrint :: (MonadIO m, Show a) => a -> m ()
pPrint :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrint = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pHPrint :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrint :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrint = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pPrintString :: MonadIO m => String -> m ()
pPrintString :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintString = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pHPrintString :: MonadIO m => Handle -> String -> m ()
pHPrintString :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintString = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pPrintForceColor :: (MonadIO m, Show a) => a -> m ()
pPrintForceColor :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintForceColor = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pHPrintForceColor :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColor :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColor = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pPrintStringForceColor :: MonadIO m => String -> m ()
pPrintStringForceColor :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringForceColor = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pHPrintStringForceColor :: MonadIO m => Handle -> String -> m ()
pHPrintStringForceColor :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringForceColor = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsDarkBg
pShow :: Show a => a -> Text
pShow :: forall a. Show a => a -> Text
pShow = forall a. Show a => OutputOptions -> a -> Text
pShowOpt OutputOptions
defaultOutputOptionsDarkBg
pString :: String -> Text
pString :: String -> Text
pString = OutputOptions -> String -> Text
pStringOpt OutputOptions
defaultOutputOptionsDarkBg
pPrintDarkBg :: (MonadIO m, Show a) => a -> m ()
pPrintDarkBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintDarkBg = forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrint
pHPrintDarkBg :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintDarkBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintDarkBg = forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrint
pPrintStringDarkBg :: MonadIO m => String -> m ()
pPrintStringDarkBg :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringDarkBg = forall (m :: * -> *). MonadIO m => String -> m ()
pPrintString
pHPrintStringDarkBg :: MonadIO m => Handle -> String -> m ()
pHPrintStringDarkBg :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringDarkBg = forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintString
pPrintForceColorDarkBg :: (MonadIO m, Show a) => a -> m ()
pPrintForceColorDarkBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintForceColorDarkBg = forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintForceColor
pHPrintForceColorDarkBg :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColorDarkBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColorDarkBg = forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColor
pPrintStringForceColorDarkBg :: MonadIO m => String -> m ()
pPrintStringForceColorDarkBg :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringForceColorDarkBg = forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringForceColor
pHPrintStringForceColorDarkBg :: MonadIO m => Handle -> String -> m ()
pHPrintStringForceColorDarkBg :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringForceColorDarkBg = forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringForceColor
pShowDarkBg :: Show a => a -> Text
pShowDarkBg :: forall a. Show a => a -> Text
pShowDarkBg = forall a. Show a => a -> Text
pShow
pStringDarkBg :: String -> Text
pStringDarkBg :: String -> Text
pStringDarkBg = String -> Text
pString
pPrintLightBg :: (MonadIO m, Show a) => a -> m ()
pPrintLightBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintLightBg = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsLightBg
pHPrintLightBg :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintLightBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintLightBg = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsLightBg
pPrintStringLightBg :: MonadIO m => String -> m ()
pPrintStringLightBg :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringLightBg = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsLightBg
pHPrintStringLightBg :: MonadIO m => Handle -> String -> m ()
pHPrintStringLightBg :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringLightBg = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
CheckColorTty OutputOptions
defaultOutputOptionsLightBg
pPrintForceColorLightBg :: (MonadIO m, Show a) => a -> m ()
pPrintForceColorLightBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintForceColorLightBg = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsLightBg
pHPrintForceColorLightBg :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColorLightBg :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintForceColorLightBg = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsLightBg
pPrintStringForceColorLightBg :: MonadIO m => String -> m ()
pPrintStringForceColorLightBg :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringForceColorLightBg = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsLightBg
pHPrintStringForceColorLightBg :: MonadIO m => Handle -> String -> m ()
pHPrintStringForceColorLightBg :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringForceColorLightBg = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsLightBg
pShowLightBg :: Show a => a -> Text
pShowLightBg :: forall a. Show a => a -> Text
pShowLightBg = forall a. Show a => OutputOptions -> a -> Text
pShowOpt OutputOptions
defaultOutputOptionsLightBg
pStringLightBg :: String -> Text
pStringLightBg :: String -> Text
pStringLightBg = OutputOptions -> String -> Text
pStringOpt OutputOptions
defaultOutputOptionsLightBg
pPrintNoColor :: (MonadIO m, Show a) => a -> m ()
pPrintNoColor :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
pPrintNoColor = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsNoColor
pHPrintNoColor :: (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintNoColor :: forall (m :: * -> *) a. (MonadIO m, Show a) => Handle -> a -> m ()
pHPrintNoColor = forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsNoColor
pPrintStringNoColor :: MonadIO m => String -> m ()
pPrintStringNoColor :: forall (m :: * -> *). MonadIO m => String -> m ()
pPrintStringNoColor = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsNoColor
pHPrintStringNoColor :: MonadIO m => Handle -> String -> m ()
pHPrintStringNoColor :: forall (m :: * -> *). MonadIO m => Handle -> String -> m ()
pHPrintStringNoColor = forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
NoCheckColorTty OutputOptions
defaultOutputOptionsNoColor
pShowNoColor :: Show a => a -> Text
pShowNoColor :: forall a. Show a => a -> Text
pShowNoColor = forall a. Show a => OutputOptions -> a -> Text
pShowOpt OutputOptions
defaultOutputOptionsNoColor
pStringNoColor :: String -> Text
pStringNoColor :: String -> Text
pStringNoColor = OutputOptions -> String -> Text
pStringOpt OutputOptions
defaultOutputOptionsNoColor
pPrintOpt :: (MonadIO m, Show a) => CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt :: forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> a -> m ()
pPrintOpt CheckColorTty
checkColorTty OutputOptions
outputOptions =
forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
checkColorTty OutputOptions
outputOptions Handle
stdout
pHPrintOpt ::
(MonadIO m, Show a)
=> CheckColorTty
-> OutputOptions
-> Handle
-> a
-> m ()
pHPrintOpt :: forall (m :: * -> *) a.
(MonadIO m, Show a) =>
CheckColorTty -> OutputOptions -> Handle -> a -> m ()
pHPrintOpt CheckColorTty
checkColorTty OutputOptions
outputOptions Handle
handle a
a =
forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
checkColorTty OutputOptions
outputOptions Handle
handle forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show a
a
pPrintStringOpt :: MonadIO m => CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt :: forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> String -> m ()
pPrintStringOpt CheckColorTty
checkColorTty OutputOptions
outputOptions =
forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
checkColorTty OutputOptions
outputOptions Handle
stdout
pHPrintStringOpt ::
MonadIO m
=> CheckColorTty
-> OutputOptions
-> Handle
-> String
-> m ()
pHPrintStringOpt :: forall (m :: * -> *).
MonadIO m =>
CheckColorTty -> OutputOptions -> Handle -> String -> m ()
pHPrintStringOpt CheckColorTty
checkColorTty OutputOptions
outputOptions Handle
handle String
str = do
OutputOptions
realOutputOpts <-
case CheckColorTty
checkColorTty of
CheckColorTty
CheckColorTty -> forall (m :: * -> *).
MonadIO m =>
Handle -> OutputOptions -> m OutputOptions
hCheckTTY Handle
handle OutputOptions
outputOptions
CheckColorTty
NoCheckColorTty -> forall (f :: * -> *) a. Applicative f => a -> f a
pure OutputOptions
outputOptions
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
Handle -> SimpleDocStream AnsiStyle -> IO ()
renderIO Handle
handle forall a b. (a -> b) -> a -> b
$ OutputOptions -> String -> SimpleDocStream AnsiStyle
layoutStringAnsi OutputOptions
realOutputOpts String
str
Handle -> String -> IO ()
hPutStrLn Handle
handle String
""
pShowOpt :: Show a => OutputOptions -> a -> Text
pShowOpt :: forall a. Show a => OutputOptions -> a -> Text
pShowOpt OutputOptions
outputOptions = OutputOptions -> String -> Text
pStringOpt OutputOptions
outputOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
pStringOpt :: OutputOptions -> String -> Text
pStringOpt :: OutputOptions -> String -> Text
pStringOpt OutputOptions
outputOptions = SimpleDocStream AnsiStyle -> Text
renderLazy forall b c a. (b -> c) -> (a -> b) -> a -> c
. OutputOptions -> String -> SimpleDocStream AnsiStyle
layoutStringAnsi OutputOptions
outputOptions
layoutStringAnsi :: OutputOptions -> String -> SimpleDocStream AnsiStyle
layoutStringAnsi :: OutputOptions -> String -> SimpleDocStream AnsiStyle
layoutStringAnsi OutputOptions
opts = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Style -> AnsiStyle
convertStyle forall b c a. (b -> c) -> (a -> b) -> a -> c
. OutputOptions -> String -> SimpleDocStream Style
layoutString OutputOptions
opts