{-# LANGUAGE CPP #-}
module Debug.Pretty.Simple
(
pTrace
, pTraceId
, pTraceShow
, pTraceShowId
, pTraceIO
, pTraceM
, pTraceShowM
, pTraceStack
, pTraceEvent
, pTraceEventIO
, pTraceMarker
, pTraceMarkerIO
, pTraceForceColor
, pTraceIdForceColor
, pTraceShowForceColor
, pTraceShowIdForceColor
, pTraceMForceColor
, pTraceShowMForceColor
, pTraceStackForceColor
, pTraceEventForceColor
, pTraceEventIOForceColor
, pTraceMarkerForceColor
, pTraceMarkerIOForceColor
, pTraceIOForceColor
, pTraceNoColor
, pTraceIdNoColor
, pTraceShowNoColor
, pTraceShowIdNoColor
, pTraceMNoColor
, pTraceShowMNoColor
, pTraceStackNoColor
, pTraceEventNoColor
, pTraceEventIONoColor
, pTraceMarkerNoColor
, pTraceMarkerIONoColor
, pTraceIONoColor
, pTraceOpt
, pTraceIdOpt
, pTraceShowOpt
, pTraceShowIdOpt
, pTraceOptIO
, pTraceOptM
, pTraceShowOptM
, pTraceStackOpt
, pTraceEventOpt
, pTraceEventOptIO
, pTraceMarkerOpt
, pTraceMarkerOptIO
) where
import Control.Monad ((<=<))
import Data.Text.Lazy (Text, unpack)
import Debug.Trace
(trace, traceEvent, traceEventIO, traceIO, traceM, traceMarker,
traceMarkerIO, traceStack)
import System.IO (stderr)
import System.IO.Unsafe (unsafePerformIO)
import Text.Pretty.Simple
(CheckColorTty(..), OutputOptions, pStringOpt,
defaultOutputOptionsNoColor, defaultOutputOptionsDarkBg)
import Text.Pretty.Simple.Internal (hCheckTTY)
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
pTraceIO :: String -> IO ()
pTraceIO = pTraceOptIO CheckColorTty defaultOutputOptionsDarkBg
pTrace :: String -> a -> a
pTrace = pTraceOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceId :: String -> String
pTraceId = pTraceIdOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceShow :: (Show a) => a -> b -> b
pTraceShow = pTraceShowOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceShowId :: (Show a) => a -> a
pTraceShowId = pTraceShowIdOpt CheckColorTty defaultOutputOptionsDarkBg
#if __GLASGOW_HASKELL__ < 800
pTraceM :: (Monad f) => String -> f ()
#else
pTraceM :: (Applicative f) => String -> f ()
#endif
pTraceM = pTraceOptM CheckColorTty defaultOutputOptionsDarkBg
#if __GLASGOW_HASKELL__ < 800
pTraceShowM :: (Show a, Monad f) => a -> f ()
#else
pTraceShowM :: (Show a, Applicative f) => a -> f ()
#endif
pTraceShowM = pTraceShowOptM CheckColorTty defaultOutputOptionsDarkBg
pTraceStack :: String -> a -> a
pTraceStack = pTraceStackOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceEvent :: String -> a -> a
pTraceEvent = pTraceEventOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceEventIO :: String -> IO ()
pTraceEventIO = pTraceEventOptIO CheckColorTty defaultOutputOptionsDarkBg
pTraceMarker :: String -> a -> a
pTraceMarker = pTraceMarkerOpt CheckColorTty defaultOutputOptionsDarkBg
pTraceMarkerIO :: String -> IO ()
pTraceMarkerIO = pTraceMarkerOptIO CheckColorTty defaultOutputOptionsDarkBg
pStringTTYOptIO :: CheckColorTty -> OutputOptions -> String -> IO Text
pStringTTYOptIO checkColorTty outputOptions v = do
realOutputOpts <-
case checkColorTty of
CheckColorTty -> hCheckTTY stderr outputOptions
NoCheckColorTty -> pure outputOptions
pure $ pStringOpt realOutputOpts v
pStringTTYOpt :: CheckColorTty -> OutputOptions -> String -> Text
pStringTTYOpt checkColorTty outputOptions =
unsafePerformIO . pStringTTYOptIO checkColorTty outputOptions
pShowTTYOptIO :: Show a => CheckColorTty -> OutputOptions -> a -> IO Text
pShowTTYOptIO checkColorTty outputOptions =
pStringTTYOptIO checkColorTty outputOptions . show
pShowTTYOpt :: Show a => CheckColorTty -> OutputOptions -> a -> Text
pShowTTYOpt checkColorTty outputOptions =
unsafePerformIO . pShowTTYOptIO checkColorTty outputOptions
pTraceForceColor :: String -> a -> a
pTraceForceColor = pTraceOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceIdForceColor :: String -> String
pTraceIdForceColor = pTraceIdOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceShowForceColor :: (Show a) => a -> b -> b
pTraceShowForceColor = pTraceShowOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceShowIdForceColor :: (Show a) => a -> a
pTraceShowIdForceColor =
pTraceShowIdOpt NoCheckColorTty defaultOutputOptionsDarkBg
#if __GLASGOW_HASKELL__ < 800
pTraceMForceColor :: (Monad f) => String -> f ()
#else
pTraceMForceColor :: (Applicative f) => String -> f ()
#endif
pTraceMForceColor = pTraceOptM NoCheckColorTty defaultOutputOptionsDarkBg
#if __GLASGOW_HASKELL__ < 800
pTraceShowMForceColor :: (Show a, Monad f) => a -> f ()
#else
pTraceShowMForceColor :: (Show a, Applicative f) => a -> f ()
#endif
pTraceShowMForceColor =
pTraceShowOptM NoCheckColorTty defaultOutputOptionsDarkBg
pTraceStackForceColor :: String -> a -> a
pTraceStackForceColor =
pTraceStackOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceEventForceColor :: String -> a -> a
pTraceEventForceColor =
pTraceEventOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceEventIOForceColor :: String -> IO ()
pTraceEventIOForceColor =
pTraceEventOptIO NoCheckColorTty defaultOutputOptionsDarkBg
pTraceMarkerForceColor :: String -> a -> a
pTraceMarkerForceColor =
pTraceMarkerOpt NoCheckColorTty defaultOutputOptionsDarkBg
pTraceMarkerIOForceColor :: String -> IO ()
pTraceMarkerIOForceColor =
pTraceMarkerOptIO NoCheckColorTty defaultOutputOptionsDarkBg
pTraceIOForceColor :: String -> IO ()
pTraceIOForceColor = pTraceOptIO NoCheckColorTty defaultOutputOptionsDarkBg
pTraceNoColor :: String -> a -> a
pTraceNoColor = pTraceOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceIdNoColor :: String -> String
pTraceIdNoColor = pTraceIdOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceShowNoColor :: (Show a) => a -> b -> b
pTraceShowNoColor = pTraceShowOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceShowIdNoColor :: (Show a) => a -> a
pTraceShowIdNoColor =
pTraceShowIdOpt NoCheckColorTty defaultOutputOptionsNoColor
#if __GLASGOW_HASKELL__ < 800
pTraceMNoColor :: (Monad f) => String -> f ()
#else
pTraceMNoColor :: (Applicative f) => String -> f ()
#endif
pTraceMNoColor = pTraceOptM NoCheckColorTty defaultOutputOptionsNoColor
#if __GLASGOW_HASKELL__ < 800
pTraceShowMNoColor :: (Show a, Monad f) => a -> f ()
#else
pTraceShowMNoColor :: (Show a, Applicative f) => a -> f ()
#endif
pTraceShowMNoColor = pTraceShowOptM NoCheckColorTty defaultOutputOptionsNoColor
pTraceStackNoColor :: String -> a -> a
pTraceStackNoColor = pTraceStackOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceEventNoColor :: String -> a -> a
pTraceEventNoColor = pTraceEventOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceEventIONoColor :: String -> IO ()
pTraceEventIONoColor =
pTraceEventOptIO NoCheckColorTty defaultOutputOptionsNoColor
pTraceMarkerNoColor :: String -> a -> a
pTraceMarkerNoColor =
pTraceMarkerOpt NoCheckColorTty defaultOutputOptionsNoColor
pTraceMarkerIONoColor :: String -> IO ()
pTraceMarkerIONoColor =
pTraceMarkerOptIO NoCheckColorTty defaultOutputOptionsNoColor
pTraceIONoColor :: String -> IO ()
pTraceIONoColor = pTraceOptIO NoCheckColorTty defaultOutputOptionsNoColor
pTraceOpt :: CheckColorTty -> OutputOptions -> String -> a -> a
pTraceOpt checkColorTty outputOptions =
trace . unpack . pStringTTYOpt checkColorTty outputOptions
pTraceIdOpt :: CheckColorTty -> OutputOptions -> String -> String
pTraceIdOpt checkColorTty outputOptions a =
pTraceOpt checkColorTty outputOptions a a
pTraceShowOpt :: (Show a) => CheckColorTty -> OutputOptions -> a -> b -> b
pTraceShowOpt checkColorTty outputOptions =
trace . unpack . pShowTTYOpt checkColorTty outputOptions
pTraceShowIdOpt :: (Show a) => CheckColorTty -> OutputOptions -> a -> a
pTraceShowIdOpt checkColorTty outputOptions a =
trace (unpack $ pShowTTYOpt checkColorTty outputOptions a) a
pTraceOptIO :: CheckColorTty -> OutputOptions -> String -> IO ()
pTraceOptIO checkColorTty outputOptions =
traceIO . unpack <=< pStringTTYOptIO checkColorTty outputOptions
#if __GLASGOW_HASKELL__ < 800
pTraceOptM :: (Monad f) => CheckColorTty -> OutputOptions -> String -> f ()
#else
pTraceOptM ::
(Applicative f) => CheckColorTty -> OutputOptions -> String -> f ()
#endif
pTraceOptM checkColorTty outputOptions string =
trace (unpack $ pStringTTYOpt checkColorTty outputOptions string) $ pure ()
#if __GLASGOW_HASKELL__ < 800
pTraceShowOptM ::
(Show a, Monad f) => CheckColorTty -> OutputOptions -> a -> f ()
#else
pTraceShowOptM ::
(Show a, Applicative f) => CheckColorTty -> OutputOptions -> a -> f ()
#endif
pTraceShowOptM checkColorTty outputOptions =
traceM . unpack . pShowTTYOpt checkColorTty outputOptions
pTraceStackOpt :: CheckColorTty -> OutputOptions -> String -> a -> a
pTraceStackOpt checkColorTty outputOptions =
traceStack . unpack . pStringTTYOpt checkColorTty outputOptions
pTraceEventOpt :: CheckColorTty -> OutputOptions -> String -> a -> a
pTraceEventOpt checkColorTty outputOptions =
traceEvent . unpack . pStringTTYOpt checkColorTty outputOptions
pTraceEventOptIO :: CheckColorTty -> OutputOptions -> String -> IO ()
pTraceEventOptIO checkColorTty outputOptions =
traceEventIO . unpack <=< pStringTTYOptIO checkColorTty outputOptions
pTraceMarkerOpt :: CheckColorTty -> OutputOptions -> String -> a -> a
pTraceMarkerOpt checkColorTty outputOptions =
traceMarker . unpack . pStringTTYOpt checkColorTty outputOptions
pTraceMarkerOptIO :: CheckColorTty -> OutputOptions -> String -> IO ()
pTraceMarkerOptIO checkColorTty outputOptions =
traceMarkerIO . unpack <=< pStringTTYOptIO checkColorTty outputOptions