    {-# LANGUAGE NoImplicitPrelude #-}
    {-# LANGUAGE FlexibleContexts  #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE OverloadedStrings #-}

    module RIO.PrettyPrint
      (
        -- * Type classes for optionally colored terminal output

        HasTerm (..)
      , HasStylesUpdate (..)
        -- * Pretty printing functions

      , displayPlain
      , displayWithColor
        -- * Logging based on pretty-print typeclass

        -- | The @pretty...@ functions come in three varieties:

        --

        -- * The normal variety, with a single styled document;

        -- * The @L@ variety. The listed styled documents are concatenated with

        --   'fillSep'; and

        -- * The @S@ variety. 'flow' is applied to the 'String'.

        --

        -- Pretty message at log level 'LevelDebug'.

      , prettyDebug
      , prettyDebugL
      , prettyDebugS
        -- | Pretty message at log level 'LevelInfo'.

      , prettyInfo
      , prettyInfoL
      , prettyInfoS
        -- | Pretty messages at log level 'LevelInfo', starting on a new line with

        -- label @Note:@, with the message indented after the label.

      , prettyNote
      , prettyNoteL
      , prettyNoteS
        -- | Pretty messages at log level 'LevelWarn', starting on a new line with

        -- label @Warning:@, with or without the message indented after the label.

      , prettyWarn
      , prettyWarnL
      , prettyWarnS
      , prettyWarnNoIndent
      , prettyWarnNoIndentL
      , prettyWarnNoIndentS
        -- | Pretty messages at log level 'LevelError', starting on a new line with

        -- label @Error:@, with or without the message indented after the label.

      , prettyError
      , prettyErrorL
      , prettyErrorS
      , prettyErrorNoIndent
      , prettyErrorNoIndentL
      , prettyErrorNoIndentS
        -- | Pretty messages at the specified log level.

      , prettyGeneric
      , prettyWith

        -- * Semantic styling functions

        -- | These are used rather than applying colors or other styling directly,

        -- to provide consistency.

      , style
      , displayMilliseconds
      , logLevelToStyle
        -- * Formatting utils

      , blankLine
      , bulletedList
      , spacedBulletedList
      , mkBulletedList
      , mkNarrativeList
      , debugBracket
        -- * Re-exports from "Text.PrettyPrint.Leijen.Extended"

      , Pretty (..)
      , StyleDoc (..)
      , StyleAnn (..)
      , nest
      , line
      , linebreak
      , group
      , softline
      , softbreak
      , align
      , hang
      , indent
      , encloseSep
      , (<+>)
      , hsep
      , vsep
      , fillSep
      , sep
      , hcat
      , vcat
      , fillCat
      , cat
      , punctuate
      , fill
      , fillBreak
      , enclose
      , squotes
      , dquotes
      , parens
      , angles
      , braces
      , brackets
      , string
      , indentAfterLabel
      , wordDocs
      , flow
        -- * Re-exports from "RIO.PrettyPrint.Types.PrettyPrint"

      , Style (..)
      ) where

    import           Data.List ( intersperse )
    import           RIO
    import           RIO.PrettyPrint.StylesUpdate ( HasStylesUpdate (..) )
    import           RIO.PrettyPrint.Types ( Style (..) )
    import           Text.PrettyPrint.Leijen.Extended
                       ( Pretty (pretty), StyleAnn (..), StyleDoc, (<+>), align
                       , angles, braces, brackets, cat, displayAnsi, displayPlain
                       , dquotes, enclose, encloseSep, fill, fillBreak, fillCat
                       , fillSep, group, hang, hcat, hsep, indent, line, linebreak
                       , nest, parens, punctuate, sep, softbreak, softline, squotes
                       , string, styleAnn, vcat, vsep
                       )

    class (HasLogFunc env, HasStylesUpdate env) => HasTerm env where
      useColorL :: Lens' env Bool
      termWidthL :: Lens' env Int

    displayWithColor ::
         (HasTerm env, Pretty a, MonadReader env m, HasCallStack)
      => a
      -> m Utf8Builder
    displayWithColor :: forall env a (m :: * -> *).
    (HasTerm env, Pretty a, MonadReader env m, HasCallStack) =>
    a -> m Utf8Builder
    displayWithColor a
    x = do
      useAnsi <- Getting Bool env Bool -> m Bool
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting Bool env Bool
    forall env. HasTerm env => Lens' env Bool
    Lens' env Bool
    useColorL
      termWidth <- view termWidthL
      (if useAnsi then displayAnsi else displayPlain) termWidth x

    -- TODO: switch to using implicit callstacks once 7.8 support is dropped

    prettyGeneric ::
         (HasTerm env, HasCallStack, Pretty b, MonadReader env m, MonadIO m)
      => LogLevel
      -> b
      -> m ()
    prettyGeneric :: forall env b (m :: * -> *).
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> b -> m ()
    prettyGeneric LogLevel
    level = LogLevel -> (b -> b) -> b -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    level b -> b
    forall a. a -> a
    id

    prettyWith ::
         (HasTerm env, HasCallStack, Pretty b, MonadReader env m, MonadIO m)
      => LogLevel
      -> (a -> b)
      -> a
      -> m ()
    prettyWith :: forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    level a -> b
    f = LogSource -> LogLevel -> Utf8Builder -> m ()
    forall (m :: * -> *) env.
    (MonadIO m, MonadReader env m, HasLogFunc env, HasCallStack) =>
    LogSource -> LogLevel -> Utf8Builder -> m ()
    logGeneric LogSource
    "" LogLevel
    level (Utf8Builder -> m ())
    -> (Utf8Builder -> Utf8Builder) -> Utf8Builder -> m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Utf8Builder -> Utf8Builder
    forall a. Display a => a -> Utf8Builder
    RIO.display (Utf8Builder -> m ()) -> (a -> m Utf8Builder) -> a -> m ()
    forall (m :: * -> *) b c a.
    Monad m =>
    (b -> m c) -> (a -> m b) -> a -> m c
    <=< b -> m Utf8Builder
    forall env a (m :: * -> *).
    (HasTerm env, Pretty a, MonadReader env m, HasCallStack) =>
    a -> m Utf8Builder
    displayWithColor (b -> m Utf8Builder) -> (a -> b) -> a -> m Utf8Builder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> b
    f

    -- Note: I think keeping this section aligned helps spot errors, might be

    -- worth keeping the alignment in place.

    prettyDebugWith, prettyInfoWith, prettyNoteWith, prettyWarnWith, prettyErrorWith, prettyWarnNoIndentWith, prettyErrorNoIndentWith
      :: (HasCallStack, HasTerm env, MonadReader env m, MonadIO m)
      => (a -> StyleDoc) -> a -> m ()
    prettyDebugWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyDebugWith = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelDebug
    prettyInfoWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyInfoWith  = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelInfo
    prettyNoteWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyNoteWith a -> StyleDoc
    f  = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelInfo
                              ((StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Style -> StyleDoc -> StyleDoc
    style Style
    Good StyleDoc
    "Note:" StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                               StyleDoc -> StyleDoc
    indentAfterLabel (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StyleDoc
    f)
    prettyWarnWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnWith a -> StyleDoc
    f  = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelWarn
                              ((StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Style -> StyleDoc -> StyleDoc
    style Style
    Warning StyleDoc
    "Warning:" StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                               StyleDoc -> StyleDoc
    indentAfterLabel (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StyleDoc
    f)
    prettyErrorWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorWith a -> StyleDoc
    f = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelError
                              ((StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Style -> StyleDoc -> StyleDoc
    style Style
    Error   StyleDoc
    "Error:" StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                               StyleDoc -> StyleDoc
    indentAfterLabel (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StyleDoc
    f)
    prettyWarnNoIndentWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnNoIndentWith a -> StyleDoc
    f  = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelWarn
                                      ((StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Style -> StyleDoc -> StyleDoc
    style Style
    Warning StyleDoc
    "Warning:" StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StyleDoc
    f)
    prettyErrorNoIndentWith :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorNoIndentWith a -> StyleDoc
    f = LogLevel -> (a -> StyleDoc) -> a -> m ()
    forall env b (m :: * -> *) a.
    (HasTerm env, HasCallStack, Pretty b, MonadReader env m,
     MonadIO m) =>
    LogLevel -> (a -> b) -> a -> m ()
    prettyWith LogLevel
    LevelError
                                      ((StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Style -> StyleDoc -> StyleDoc
    style Style
    Error   StyleDoc
    "Error:" StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc) -> (a -> StyleDoc) -> a -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StyleDoc
    f)

    prettyDebug, prettyInfo, prettyNote, prettyWarn, prettyError, prettyWarnNoIndent, prettyErrorNoIndent
      :: (HasCallStack, HasTerm env, MonadReader env m, MonadIO m)
      => StyleDoc -> m ()
    prettyDebug :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyDebug         = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyDebugWith         StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyInfo :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyInfo          = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyInfoWith          StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyNote :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyNote          = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyNoteWith          StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyWarn :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyWarn          = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnWith          StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyError :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyError         = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorWith         StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyWarnNoIndent :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyWarnNoIndent  = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnNoIndentWith  StyleDoc -> StyleDoc
    forall a. a -> a
    id
    prettyErrorNoIndent :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    StyleDoc -> m ()
    prettyErrorNoIndent = (StyleDoc -> StyleDoc) -> StyleDoc -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorNoIndentWith StyleDoc -> StyleDoc
    forall a. a -> a
    id

    prettyDebugL, prettyInfoL, prettyNoteL, prettyWarnL, prettyErrorL, prettyWarnNoIndentL, prettyErrorNoIndentL
      :: (HasCallStack, HasTerm env, MonadReader env m, MonadIO m)
      => [StyleDoc] -> m ()
    prettyDebugL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyDebugL         = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyDebugWith         [StyleDoc] -> StyleDoc
    fillSep
    prettyInfoL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyInfoL          = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyInfoWith          [StyleDoc] -> StyleDoc
    fillSep
    prettyNoteL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyNoteL          = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyNoteWith          [StyleDoc] -> StyleDoc
    fillSep
    prettyWarnL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyWarnL          = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnWith          [StyleDoc] -> StyleDoc
    fillSep
    prettyErrorL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyErrorL         = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorWith         [StyleDoc] -> StyleDoc
    fillSep
    prettyWarnNoIndentL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyWarnNoIndentL  = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnNoIndentWith  [StyleDoc] -> StyleDoc
    fillSep
    prettyErrorNoIndentL :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    [StyleDoc] -> m ()
    prettyErrorNoIndentL = ([StyleDoc] -> StyleDoc) -> [StyleDoc] -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorNoIndentWith [StyleDoc] -> StyleDoc
    fillSep

    prettyDebugS, prettyInfoS, prettyNoteS, prettyWarnS, prettyErrorS, prettyWarnNoIndentS, prettyErrorNoIndentS
      :: (HasCallStack, HasTerm env, MonadReader env m, MonadIO m)
      => String -> m ()
    prettyDebugS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyDebugS         = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyDebugWith         String -> StyleDoc
    flow
    prettyInfoS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyInfoS          = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyInfoWith          String -> StyleDoc
    flow
    prettyNoteS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyNoteS          = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyNoteWith          String -> StyleDoc
    flow
    prettyWarnS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyWarnS          = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnWith          String -> StyleDoc
    flow
    prettyErrorS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyErrorS         = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorWith         String -> StyleDoc
    flow
    prettyWarnNoIndentS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyWarnNoIndentS  = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyWarnNoIndentWith  String -> StyleDoc
    flow
    prettyErrorNoIndentS :: forall env (m :: * -> *).
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    String -> m ()
    prettyErrorNoIndentS = (String -> StyleDoc) -> String -> m ()
    forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m) =>
    (a -> StyleDoc) -> a -> m ()
    prettyErrorNoIndentWith String -> StyleDoc
    flow

    -- End of aligned section

    -- | Use after a label and before the rest of what's being labelled for

    --   consistent spacing/indenting/etc.

    --

    --   For example this is used after "Warning:" in warning messages.

    indentAfterLabel :: StyleDoc -> StyleDoc
    indentAfterLabel :: StyleDoc -> StyleDoc
    indentAfterLabel = StyleDoc -> StyleDoc
    align

    -- | Make a 'StyleDoc' from each word in a 'String'

    wordDocs :: String -> [StyleDoc]
    wordDocs :: String -> [StyleDoc]
    wordDocs = (String -> StyleDoc) -> [String] -> [StyleDoc]
    forall a b. (a -> b) -> [a] -> [b]
    map String -> StyleDoc
    forall a. IsString a => String -> a
    fromString ([String] -> [StyleDoc])
    -> (String -> [String]) -> String -> [StyleDoc]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> [String]
    words

    -- | Wordwrap a 'String'

    flow :: String -> StyleDoc
    flow :: String -> StyleDoc
    flow = [StyleDoc] -> StyleDoc
    fillSep ([StyleDoc] -> StyleDoc)
    -> (String -> [StyleDoc]) -> String -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> [StyleDoc]
    wordDocs

    -- | A blank line.

    blankLine :: StyleDoc
    blankLine :: StyleDoc
    blankLine = StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    line

    -- | @debug message action@ brackets any output of the specified @action@ with

    -- an initial and final @message@ at log level 'LevelDebug'. The initial message

    -- is prefixed with the label @Start:@. The final message is prefixed with

    -- information about the duration of the action in milliseconds (ms) and, if

    -- an exception is thrown by the action, the exception. For example:

    --

    -- > Start: <message>

    -- > <output of action>

    -- > Finished in ...ms: <message>

    --

    -- or:

    --

    -- > Start: <message>

    -- > <output of action>

    -- > Finished with exception in ...ms: <message>

    -- > Exception thrown: <exception_message>

    debugBracket :: (HasCallStack, HasTerm env, MonadReader env m,
                     MonadIO m, MonadUnliftIO m) => StyleDoc -> m a -> m a
    debugBracket :: forall env (m :: * -> *) a.
    (HasCallStack, HasTerm env, MonadReader env m, MonadIO m,
     MonadUnliftIO m) =>
    StyleDoc -> m a -> m a
    debugBracket StyleDoc
    msg m a
    f = do
      let output :: StyleDoc -> m ()
    output = Utf8Builder -> m ()
    forall (m :: * -> *) env.
    (MonadIO m, MonadReader env m, HasLogFunc env, HasCallStack) =>
    Utf8Builder -> m ()
    logDebug (Utf8Builder -> m ())
    -> (Utf8Builder -> Utf8Builder) -> Utf8Builder -> m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Utf8Builder -> Utf8Builder
    forall a. Display a => a -> Utf8Builder
    RIO.display (Utf8Builder -> m ())
    -> (StyleDoc -> m Utf8Builder) -> StyleDoc -> m ()
    forall (m :: * -> *) b c a.
    Monad m =>
    (b -> m c) -> (a -> m b) -> a -> m c
    <=< StyleDoc -> m Utf8Builder
    forall env a (m :: * -> *).
    (HasTerm env, Pretty a, MonadReader env m, HasCallStack) =>
    a -> m Utf8Builder
    displayWithColor
      StyleDoc -> m ()
    output (StyleDoc -> m ()) -> StyleDoc -> m ()
    forall a b. (a -> b) -> a -> b
    $ StyleDoc
    "Start: " StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    msg
      start <- m Double
    forall (m :: * -> *). MonadIO m => m Double
    getMonotonicTime
      x <- f `catch` \SomeException
    ex -> do
        end <- m Double
    forall (m :: * -> *). MonadIO m => m Double
    getMonotonicTime
        let diff = Double
    end Double -> Double -> Double
    forall a. Num a => a -> a -> a
    - Double
    start
        output $
             "Finished with exception in"
          <+> displayMilliseconds diff <> ":"
          <+> msg
          <> line
          <> "Exception thrown: "
          <> fromString (show ex)
        throwIO (ex :: SomeException)
      end <- getMonotonicTime
      let diff = Double
    end Double -> Double -> Double
    forall a. Num a => a -> a -> a
    - Double
    start
      output $ "Finished in" <+> displayMilliseconds diff <> ":" <+> msg
      return x

    -- | Annotate a 'StyleDoc' with a 'Style'.

    style :: Style -> StyleDoc -> StyleDoc
    style :: Style -> StyleDoc -> StyleDoc
    style = Style -> StyleDoc -> StyleDoc
    styleAnn

    -- | Display as milliseconds in style 'Good'.

    displayMilliseconds ::
         Double
         -- ^ Amount of time in seconds.

      -> StyleDoc
    displayMilliseconds :: Double -> StyleDoc
    displayMilliseconds Double
    t = Style -> StyleDoc -> StyleDoc
    style Style
    Good (StyleDoc -> StyleDoc) -> StyleDoc -> StyleDoc
    forall a b. (a -> b) -> a -> b
    $
      String -> StyleDoc
    forall a. IsString a => String -> a
    fromString (Int -> String
    forall a. Show a => a -> String
    show (Double -> Int
    forall b. Integral b => Double -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    round (Double
    t Double -> Double -> Double
    forall a. Num a => a -> a -> a
    * Double
    1000) :: Int)) StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    "ms"

    -- | Display a bulleted list of 'StyleDoc' with @*@ as the bullet point.

    bulletedList :: [StyleDoc] -> StyleDoc
    bulletedList :: [StyleDoc] -> StyleDoc
    bulletedList = Bool -> Char -> [StyleDoc] -> StyleDoc
    mkBulletedList Bool
    False Char
    '*'

    -- | Display a bulleted list of 'StyleDoc', spaced with blank lines or not,

    -- given a character for the bullet point.

    --

    -- @since 0.1.6.0

    mkBulletedList ::
         Bool
         -- ^ Spaced with a blank line between each item?

      -> Char
         -- ^ The character to act as the bullet point.

      -> [StyleDoc]
      -> StyleDoc
    mkBulletedList :: Bool -> Char -> [StyleDoc] -> StyleDoc
    mkBulletedList Bool
    isSpaced Char
    bullet =
      [StyleDoc] -> StyleDoc
    forall a. Monoid a => [a] -> a
    mconcat ([StyleDoc] -> StyleDoc)
    -> ([StyleDoc] -> [StyleDoc]) -> [StyleDoc] -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StyleDoc -> [StyleDoc] -> [StyleDoc]
    forall a. a -> [a] -> [a]
    intersperse StyleDoc
    spacer ([StyleDoc] -> [StyleDoc])
    -> ([StyleDoc] -> [StyleDoc]) -> [StyleDoc] -> [StyleDoc]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (StyleDoc -> StyleDoc) -> [StyleDoc] -> [StyleDoc]
    forall a b. (a -> b) -> [a] -> [b]
    map ((String -> StyleDoc
    forall a. IsString a => String -> a
    fromString [Char
    bullet] StyleDoc -> StyleDoc -> StyleDoc
    <+>) (StyleDoc -> StyleDoc)
    -> (StyleDoc -> StyleDoc) -> StyleDoc -> StyleDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StyleDoc -> StyleDoc
    align)
     where
      spacer :: StyleDoc
    spacer = if Bool
    isSpaced then StyleDoc
    line StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    line else StyleDoc
    line

    -- | A helper function to yield a narrative list from a list of items, with a

    -- final fullstop. For example, helps produce the output

    -- @\"apple, ball and cat.\"@ (no serial comma) or @\"apple, ball, and cat.\"@

    -- (serial comma) from @[\"apple\", \"ball\", \"cat\"]@.

    --

    -- @since 0.1.4.0

    mkNarrativeList ::
         Pretty a
      => Maybe Style
      -- ^ Style the items in the list?

      -> Bool
      -- ^ Use a serial comma?

      -> [a]
      -> [StyleDoc]
    mkNarrativeList :: forall a. Pretty a => Maybe Style -> Bool -> [a] -> [StyleDoc]
    mkNarrativeList Maybe Style
    _ Bool
    _ [] = []
    mkNarrativeList Maybe Style
    mStyle Bool
    _ [a
    x] = [(StyleDoc -> StyleDoc)
    -> (Style -> StyleDoc -> StyleDoc)
    -> Maybe Style
    -> StyleDoc
    -> StyleDoc
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe StyleDoc -> StyleDoc
    forall a. a -> a
    id Style -> StyleDoc -> StyleDoc
    style Maybe Style
    mStyle (a -> StyleDoc
    forall a. Pretty a => a -> StyleDoc
    pretty a
    x) StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    "."]
    mkNarrativeList Maybe Style
    mStyle Bool
    useSerialComma [a
    x1, a
    x2] =
        StyleDoc -> StyleDoc
    mStyle' (a -> StyleDoc
    forall a. Pretty a => a -> StyleDoc
    pretty a
    x1) StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> (if Bool
    useSerialComma then StyleDoc
    "," else StyleDoc
    forall a. Monoid a => a
    mempty)
      StyleDoc -> [StyleDoc] -> [StyleDoc]
    forall a. a -> [a] -> [a]
    : StyleDoc
    "and"
      StyleDoc -> [StyleDoc] -> [StyleDoc]
    forall a. a -> [a] -> [a]
    : Maybe Style -> Bool -> [a] -> [StyleDoc]
    forall a. Pretty a => Maybe Style -> Bool -> [a] -> [StyleDoc]
    mkNarrativeList Maybe Style
    mStyle Bool
    useSerialComma [a
    x2]
     where
      mStyle' :: StyleDoc -> StyleDoc
    mStyle' = (StyleDoc -> StyleDoc)
    -> (Style -> StyleDoc -> StyleDoc)
    -> Maybe Style
    -> StyleDoc
    -> StyleDoc
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe StyleDoc -> StyleDoc
    forall a. a -> a
    id Style -> StyleDoc -> StyleDoc
    style Maybe Style
    mStyle
    mkNarrativeList Maybe Style
    mStyle Bool
    useSerialComma (a
    x:[a]
    xs) =
        (StyleDoc -> StyleDoc)
    -> (Style -> StyleDoc -> StyleDoc)
    -> Maybe Style
    -> StyleDoc
    -> StyleDoc
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe StyleDoc -> StyleDoc
    forall a. a -> a
    id Style -> StyleDoc -> StyleDoc
    style Maybe Style
    mStyle (a -> StyleDoc
    forall a. Pretty a => a -> StyleDoc
    pretty a
    x) StyleDoc -> StyleDoc -> StyleDoc
    forall a. Semigroup a => a -> a -> a
    <> StyleDoc
    ","
      StyleDoc -> [StyleDoc] -> [StyleDoc]
    forall a. a -> [a] -> [a]
    : Maybe Style -> Bool -> [a] -> [StyleDoc]
    forall a. Pretty a => Maybe Style -> Bool -> [a] -> [StyleDoc]
    mkNarrativeList Maybe Style
    mStyle Bool
    useSerialComma [a]
    xs

    -- | Display a bulleted list of 'StyleDoc' with a blank line between

    -- each and @*@ as the bullet point.

    spacedBulletedList :: [StyleDoc] -> StyleDoc
    spacedBulletedList :: [StyleDoc] -> StyleDoc
    spacedBulletedList = Bool -> Char -> [StyleDoc] -> StyleDoc
    mkBulletedList Bool
    True Char
    '*'

    -- | The 'Style' intended to be associated with a 'LogLevel'.

    --

    -- @since 0.1.1.0

    logLevelToStyle :: LogLevel -> Style
    logLevelToStyle :: LogLevel -> Style
    logLevelToStyle LogLevel
    level = case LogLevel
    level of
      LogLevel
    LevelDebug   -> Style
    Debug
      LogLevel
    LevelInfo    -> Style
    Info
      LogLevel
    LevelWarn    -> Style
    Warning
      LogLevel
    LevelError   -> Style
    Error
      LevelOther LogSource
    _ -> Style
    OtherLevel