pretty-simple-4.1.4.0: pretty printer for data types with a 'Show' instance.

Copyright | (c) Dennis Gosnell 2016
License | BSD-style (see LICENSE file)
Maintainer | cdep.illabout@gmail.com
Stability | experimental
Portability | POSIX
Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Pretty.Simple

Contents

- Output with color on dark background
- Aliases for output with color on dark background
- Output with color on light background
- Output with NO color
- Output With `OutputOptions`
- `OutputOptions`
- `ColorOptions`
- Examples

Description

This module contains the functions `pPrint`, `pShow`, and `pString` for pretty-printing any Haskell data type with a `Show` instance.

`pPrint` is the main go-to function when debugging Haskell code. `pShow` and `pString` are slight variations on `pPrint`.

`pPrint`, `pShow`, and `pString` will pretty-print in color using ANSI escape codes. They look good on a console with a dark (black) background. The variations `pPrintLightBg`, `pShowLightBg`, and `pStringLightBg` are for printing in color to a console with a light (white) background. The variations `pPrintNoColor`, `pShowNoColor`, and `pStringNoColor` are for pretty-printing without using color.

`pPrint` and `pPrintLightBg` will intelligently decide whether or not to use ANSI escape codes for coloring depending on whether or not the output is a TTY. This works in most cases. If you want to force color output, you can use the `pPrintForceColor` or `pPrintForceColorLightBg` functions.

The variations `pPrintOpt`, `pShowOpt`, and `pStringOpt` are used when specifying the `OutputOptions`. Most users can ignore these.

There are a few other functions available that are similar to `pPrint`.

See the Examples section at the end of this module for examples of acutally using `pPrint`. See the README.md for examples of printing in color.

Synopsis

- pPrint :: (MonadIO m, Show a) => a -> m ()
- pHPrint :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintString :: MonadIO m => String -> m ()
- pHPrintString :: MonadIO m => Handle -> String -> m ()
- pPrintForceColor :: (MonadIO m, Show a) => a -> m ()
- pHPrintForceColor :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringForceColor :: MonadIO m => String -> m ()
- pHPrintStringForceColor :: MonadIO m => Handle -> String -> m ()
- pShow :: Show a => a -> Text
- pString :: String -> Text
- pPrintDarkBg :: (MonadIO m, Show a) => a -> m ()
- pHPrintDarkBg :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringDarkBg :: MonadIO m => String -> m ()
- pHPrintStringDarkBg :: MonadIO m => Handle -> String -> m ()
- pPrintForceColorDarkBg :: (MonadIO m, Show a) => a -> m ()
- pHPrintForceColorDarkBg :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringForceColorDarkBg :: MonadIO m => String -> m ()
- pHPrintStringForceColorDarkBg :: MonadIO m => Handle -> String -> m ()
- pShowDarkBg :: Show a => a -> Text
- pStringDarkBg :: String -> Text
- pPrintLightBg :: (MonadIO m, Show a) => a -> m ()
- pHPrintLightBg :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringLightBg :: MonadIO m => String -> m ()
- pHPrintStringLightBg :: MonadIO m => Handle -> String -> m ()
- pPrintForceColorLightBg :: (MonadIO m, Show a) => a -> m ()
- pHPrintForceColorLightBg :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringForceColorLightBg :: MonadIO m => String -> m ()
- pHPrintStringForceColorLightBg :: MonadIO m => Handle -> String -> m ()
- pShowLightBg :: Show a => a -> Text
- pStringLightBg :: String -> Text
- pPrintNoColor :: (MonadIO m, Show a) => a -> m ()
- pHPrintNoColor :: (MonadIO m, Show a) => Handle -> a -> m ()
- pPrintStringNoColor :: MonadIO m => String -> m ()
- pHPrintStringNoColor :: MonadIO m => Handle -> String -> m ()
- pShowNoColor :: Show a => a -> Text
- pStringNoColor :: String -> Text
- pPrintOpt :: (MonadIO m, Show a) => CheckColorTty -> OutputOptions -> a -> m ()
- pHPrintOpt :: (MonadIO m, Show a) => CheckColorTty -> OutputOptions -> Handle -> a -> m ()
- pPrintStringOpt :: MonadIO m => CheckColorTty -> OutputOptions -> String -> m ()
- pHPrintStringOpt :: MonadIO m => CheckColorTty -> OutputOptions -> Handle -> String -> m ()
- pShowOpt :: Show a => OutputOptions -> a -> Text
- pStringOpt :: OutputOptions -> String -> Text
- data OutputOptions = OutputOptions {
  - outputOptionsIndentAmount :: Int
  - outputOptionsPageWidth :: Int
  - outputOptionsCompact :: Bool
  - outputOptionsCompactParens :: Bool
  - outputOptionsInitialIndent :: Int
  - outputOptionsColorOptions :: Maybe ColorOptions
  - outputOptionsStringStyle :: StringOutputStyle
  }
- data StringOutputStyle
  - = Literal
  - | EscapeNonPrintable
  - | DoNotEscapeNonPrintable
- defaultOutputOptionsDarkBg :: OutputOptions
- defaultOutputOptionsLightBg :: OutputOptions
- defaultOutputOptionsNoColor :: OutputOptions
- data CheckColorTty
  - = CheckColorTty
  - | NoCheckColorTty
- defaultColorOptionsDarkBg :: ColorOptions
- defaultColorOptionsLightBg :: ColorOptions
- data ColorOptions = ColorOptions {
  - colorQuote :: Style
  - colorString :: Style
  - colorError :: Style
  - colorNum :: Style
  - colorRainbowParens :: [Style]
  }
- data Style = Style {
  - styleColor :: Maybe (Color, Intensity)
  - styleBold :: Bool
  - styleItalic :: Bool
  - styleUnderlined :: Bool
  }
- data Color
  - = Black
  - | Red
  - | Green
  - | Yellow
  - | Blue
  - | Magenta
  - | Cyan
  - | White
- data Intensity
  - = Vivid
  - | Dull
- colorNull :: Style

# Output with color on dark background

pPrint :: (MonadIO m, Show a) => a -> m () Source #

Pretty-print any data type that has a `Show` instance.

If you've never seen `MonadIO` before, you can think of this function as having the following type signature:

     pPrint :: Show a => a -> IO ()

This function will only use colors if it detects it's printing to a TTY.

This function is for printing to a dark background. Use `pPrintLightBg` for printing to a terminal with a light background. Different colors are used.

Prints to `stdout`. Use `pHPrint` to print to a different `Handle`.

    >>> pPrint [Just (1, "hello")]
    [ Just
        ( 1
        , "hello"
        )
    ]

pHPrint :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Similar to `pPrint`, but take a `Handle` to print to.

    >>> pHPrint stdout [Just (1, "hello")]
    [ Just
        ( 1
        , "hello"
        )
    ]

pPrintString :: MonadIO m => String -> m () Source #

Similar to `pPrint`, but the first argument is a `String` representing a data type that has already been `show`ed.

    >>> pPrintString $ show [ Just (1, "hello"), Nothing ]
    [ Just
        ( 1
        , "hello"
        )
    , Nothing
    ]

pHPrintString :: MonadIO m => Handle -> String -> m () Source #

Similar to `pHPrintString`, but take a `Handle` to print to.

    >>> pHPrintString stdout $ show [ Just (1, "hello"), Nothing ]
    [ Just
        ( 1
        , "hello"
        )
    , Nothing
    ]

pPrintForceColor :: (MonadIO m, Show a) => a -> m () Source #

Similar to `pPrint`, but print in color regardless of whether the output goes to a TTY or not.

See `pPrint` for an example of how to use this function.

pHPrintForceColor :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Similar to `pPrintForceColor`, but take a `Handle` to print to.

See `pHPrint` for an example of how to use this function.

pPrintStringForceColor :: MonadIO m => String -> m () Source #

Similar to `pPrintString`, but print in color regardless of whether the output goes to a TTY or not.

See `pPrintString` for an example of how to use this function.

pHPrintStringForceColor :: MonadIO m => Handle -> String -> m () Source #

Similar to `pHPrintString`, but print in color regardless of whether the output goes to a TTY or not.

See `pHPrintString` for an example of how to use this function.

pShow :: Show a => a -> Text Source #

Similar to `pPrintForceColor`, but just return the resulting pretty-printed data type as a `Text` instead of printing it to the screen.

This function is for printing to a dark background.

See `pShowNoColor` for an example of how to use this function.

pString :: String -> Text Source #

Similar to `pShow`, but the first argument is a `String` representing a data type that has already been `show`ed.

This will work on any `String` that is similar to a Haskell data type. The only requirement is that the strings are quoted, and braces, parentheses, and brackets are correctly used to represent indentation. For example, `pString` will correctly pretty-print JSON.

This function is for printing to a dark background.

See `pStringNoColor` for an example of how to use this function.

# Aliases for output with color on dark background

pPrintDarkBg :: (MonadIO m, Show a) => a -> m () Source #

Alias for `pPrint`.

pHPrintDarkBg :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Alias for `pHPrint`.

pPrintStringDarkBg :: MonadIO m => String -> m () Source #

Alias for `pPrintString`.

pHPrintStringDarkBg :: MonadIO m => Handle -> String -> m () Source #

Alias for `pHPrintString`.

pPrintForceColorDarkBg :: (MonadIO m, Show a) => a -> m () Source #

Alias for `pPrintForceColor`.

pHPrintForceColorDarkBg :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Alias for `pHPrintForceColor`.

pPrintStringForceColorDarkBg :: MonadIO m => String -> m () Source #

Alias for `pPrintStringForceColor`.

pHPrintStringForceColorDarkBg :: MonadIO m => Handle -> String -> m () Source #

Alias for `pHPrintStringForceColor`.

pShowDarkBg :: Show a => a -> Text Source #

Alias for `pShow`.

pStringDarkBg :: String -> Text Source #

Alias for `pString`.

# Output with color on light background

pPrintLightBg :: (MonadIO m, Show a) => a -> m () Source #

Just like `pPrintDarkBg`, but for printing to a light background.

pHPrintLightBg :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Just like `pHPrintDarkBg`, but for printing to a light background.

pPrintStringLightBg :: MonadIO m => String -> m () Source #

Just like `pPrintStringDarkBg`, but for printing to a light background.

pHPrintStringLightBg :: MonadIO m => Handle -> String -> m () Source #

Just like `pHPrintStringDarkBg`, but for printing to a light background.

pPrintForceColorLightBg :: (MonadIO m, Show a) => a -> m () Source #

Just like `pPrintForceColorDarkBg`, but for printing to a light background.

pHPrintForceColorLightBg :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Just like `pHPrintForceColorDarkBg`, but for printing to a light background.

pPrintStringForceColorLightBg :: MonadIO m => String -> m () Source #

Just like `pPrintStringForceColorDarkBg`, but for printing to a light background.

pHPrintStringForceColorLightBg :: MonadIO m => Handle -> String -> m () Source #

Just like `pHPrintStringForceColorDarkBg`, but for printing to a light background.

pShowLightBg :: Show a => a -> Text Source #

Just like `pShowDarkBg`, but for printing to a light background.

pStringLightBg :: String -> Text Source #

Just like `pStringDarkBg`, but for printing to a light background.

# Output with NO color

pPrintNoColor :: (MonadIO m, Show a) => a -> m () Source #

Similar to `pPrint`, but doesn't print in color. However, data types will still be indented nicely.

    >>> pPrintNoColor $ Just ["hello", "bye"]
    Just
        [ "hello"
        , "bye"
        ]

pHPrintNoColor :: (MonadIO m, Show a) => Handle -> a -> m () Source #

Like `pPrintNoColor`, but take a `Handle` to determine where to print to.

    >>> pHPrintNoColor stdout $ Just ["hello", "bye"]
    Just
        [ "hello"
        , "bye"
        ]

pPrintStringNoColor :: MonadIO m => String -> m () Source #

Similar to `pPrintString`, but doesn't print in color. However, data types will still be indented nicely.

    >>> pPrintStringNoColor $ show $ Just ["hello", "bye"]
    Just
        [ "hello"
        , "bye"
        ]

pHPrintStringNoColor :: MonadIO m => Handle -> String -> m () Source #

Like `pPrintStringNoColor`, but take a `Handle` to determine where to print to.

    >>> pHPrintStringNoColor stdout $ show $ Just ["hello", "bye"]
    Just
        [ "hello"
        , "bye"
        ]

pShowNoColor :: Show a => a -> Text Source #

Like `pShow`, but without color.

    >>> pShowNoColor [ Nothing, Just (1, "hello") ]
    "[ Nothing\n, Just\n    ( 1\n    , \"hello\"\n    )\n]"

pStringNoColor :: String -> Text Source #

LIke `pString`, but without color.

    >>> pStringNoColor $ show [1, 2, 3]
    "[ 1\n, 2\n, 3\n]"

# Output With `OutputOptions`

pPrintOpt :: (MonadIO m, Show a) => CheckColorTty -> OutputOptions -> a -> m () Source #

Similar to `pPrint` but takes `OutputOptions` to change how the pretty-printing is done.

For example, `pPrintOpt` can be used to make the indentation much smaller than normal.

This is what the normal indentation looks like:

    >>> pPrintOpt NoCheckColorTty defaultOutputOptionsNoColor $ Just ("hello", "bye")
    Just
        ( "hello"
        , "bye"
        )

This is what smaller indentation looks like:

    >>> let smallIndent = defaultOutputOptionsNoColor {outputOptionsIndentAmount = 1}
    >>> pPrintOpt CheckColorTty smallIndent $ Just ("hello", "bye")
    Just
     ( "hello"
     , "bye"
     )

Lines in strings get indented

    >>> pPrintOpt NoCheckColorTty defaultOutputOptionsNoColor (1, (2, "foo\nbar\nbaz", 3))
    ( 1
    ,
        ( 2
        , "foo
          bar
          baz"
        , 3
        )
    )

Lines get indented even in custom show instances

    >>> data Foo = Foo
    >>> instance Show Foo where show _ = "foo\nbar\nbaz"
    >>> pPrintOpt CheckColorTty defaultOutputOptionsNoColor (1, (2, Foo, 3))
    ( 1
    ,
        ( 2
        , foo
          bar
          baz
        , 3
        )
    )

`CheckColorTty` determines whether to test `stdout` for whether or not it is connected to a TTY.

If set to `NoCheckColorTty`, then `pPrintOpt` won't check if `stdout` is a TTY. It will print in color depending on the value of `outputOptionsColorOptions`.

If set to `CheckColorTty`, then `pPrintOpt` will check if `stdout` is conneted to a TTY. If `stdout` is determined to be connected to a TTY, then it will print in color depending on the value of `outputOptionsColorOptions`. If `stdout` is determined to NOT be connected to a TTY, then it will NOT print in color, regardless of the value of `outputOptionsColorOptions`.

pHPrintOpt :: (MonadIO m, Show a) => CheckColorTty -> OutputOptions -> Handle -> a -> m () Source #

Similar to `pPrintOpt`, but take a `Handle` to determine where to print to.

pPrintStringOpt :: MonadIO m => CheckColorTty -> OutputOptions -> String -> m () Source #

Similar to `pPrintOpt`, but the last argument is a string representing a data structure that has already been `show`ed.

    >>> let foo = show (1, (2, "hello", 3))
    >>> pPrintStringOpt CheckColorTty defaultOutputOptionsNoColor foo
    ( 1
    ,
        ( 2
        , "hello"
        , 3
        )
    )

pHPrintStringOpt :: MonadIO m => CheckColorTty -> OutputOptions -> Handle -> String -> m () Source #

Similar to `pPrintStringOpt`, but take a `Handle` to determine where to print to.

    >>> let foo = show (1, (2, "hello", 3))
    >>> pHPrintStringOpt CheckColorTty defaultOutputOptionsNoColor stdout foo
    ( 1
    ,
        ( 2
        , "hello"
        , 3
        )
    )

pShowOpt :: Show a => OutputOptions -> a -> Text Source #

Like `pShow` but takes `OutputOptions` to change how the pretty-printing is done.

pStringOpt :: OutputOptions -> String -> Text Source #

Like `pString` but takes `OutputOptions` to change how the pretty-printing is done.

# `OutputOptions`

data OutputOptions Source #

Data-type wrapping up all the options available when rendering the list of `Output`s.

Constructors

OutputOptions |

Fields

- outputOptionsIndentAmount :: Int

  Number of spaces to use when indenting. It should probably be either 2 or 4.

- outputOptionsPageWidth :: Int

  The maximum number of characters to fit on to one line.

- outputOptionsCompact :: Bool

  Use less vertical (and more horizontal) space.

- outputOptionsCompactParens :: Bool

  Group closing parentheses on to a single line.

- outputOptionsInitialIndent :: Int

  Indent the whole output by this amount.

- outputOptionsColorOptions :: Maybe ColorOptions

  If this is `Nothing`, then don't colorize the output. If this is ``Just` colorOptions`, then use `colorOptions` to colorize the output.

- outputOptionsStringStyle :: StringOutputStyle

  Controls how string literals are output.

  By default, the pPrint functions escape non-printable characters, but print all printable characters:

      >>> pPrintString "\"A \\x42 Ä \\xC4 \\x1 \\n\""
      "A B Ä Ä \x1
      "

  Here, you can see that the character `A` has been printed as-is. `x42` has been printed in the non-escaped version, `B`. The non-printable character `x1` has been printed as `x1`. Newlines will be removed to make the output easier to read.

  This corresponds to the `StringOutputStyle` called `EscapeNonPrintable`.

  (Note that in the above and following examples, the characters have to be double-escaped, which makes it somewhat confusing...)

  Another output style is `DoNotEscapeNonPrintable`. This is similar to `EscapeNonPrintable`, except that non-printable characters get printed out literally to the screen.

      >>> pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg{ outputOptionsStringStyle = DoNotEscapeNonPrintable } "\"A \\x42 Ä \\xC4 \\n\""
      "A B Ä Ä
      "

  If you change the above example to contain `x1`, you can see that it is output as a literal, non-escaped character. Newlines are still removed for readability.

  Another output style is `Literal`. This just outputs all escape characters.

      >>> pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg{ outputOptionsStringStyle = Literal } "\"A \\x42 Ä \\xC4 \\x1 \\n\""
      "A \x42 Ä \xC4 \x1 \n"

  You can see that all the escape characters get output literally, including newline.

#### Instances

Instances details

Generic OutputOptions Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

Associated Types

type Rep OutputOptions |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

type Rep OutputOptions = D1 ('MetaData "OutputOptions" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "OutputOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "outputOptionsIndentAmount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: (S1 ('MetaSel ('Just "outputOptionsPageWidth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "outputOptionsCompact") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "outputOptionsCompactParens") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "outputOptionsInitialIndent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "outputOptionsColorOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ColorOptions)) :*: S1 ('MetaSel ('Just "outputOptionsStringStyle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StringOutputStyle)))))

Methods

from :: OutputOptions -> Rep OutputOptions x Source #

to :: Rep OutputOptions x -> OutputOptions Source #

Show OutputOptions Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods showsPrec :: Int -> OutputOptions -> ShowS Source # show :: OutputOptions -> String Source # showList :: [OutputOptions] -> ShowS Source #
Eq OutputOptions Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods (==) :: OutputOptions -> OutputOptions -> Bool Source # (/=) :: OutputOptions -> OutputOptions -> Bool Source #
type Rep OutputOptions Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

type Rep OutputOptions = D1 ('MetaData "OutputOptions" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "OutputOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "outputOptionsIndentAmount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: (S1 ('MetaSel ('Just "outputOptionsPageWidth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "outputOptionsCompact") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "outputOptionsCompactParens") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "outputOptionsInitialIndent") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "outputOptionsColorOptions") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ColorOptions)) :*: S1 ('MetaSel ('Just "outputOptionsStringStyle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StringOutputStyle)))))

data StringOutputStyle Source #

Control how escaped and non-printable are output for strings.

See `outputOptionsStringStyle` for what the output looks like with each of these options.

Constructors

Literal | Output string literals by printing the source characters exactly. For examples: without this option the printer will insert a newline in place of `"n"`, with this options the printer will output `'\'` and ``n``. Similarly the exact escape codes used in the input string will be replicated, so `"65"` will be printed as `"65"` and not `A`.
EscapeNonPrintable | Replace non-printable characters with hexadecimal escape sequences.
DoNotEscapeNonPrintable | Output non-printable characters without modification.

#### Instances

Instances details

Generic StringOutputStyle Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

Associated Types

type Rep StringOutputStyle |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

type Rep StringOutputStyle = D1 ('MetaData "StringOutputStyle" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "Literal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "EscapeNonPrintable" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DoNotEscapeNonPrintable" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: StringOutputStyle -> Rep StringOutputStyle x Source #

to :: Rep StringOutputStyle x -> StringOutputStyle Source #

Show StringOutputStyle Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods showsPrec :: Int -> StringOutputStyle -> ShowS Source # show :: StringOutputStyle -> String Source # showList :: [StringOutputStyle] -> ShowS Source #
Eq StringOutputStyle Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods (==) :: StringOutputStyle -> StringOutputStyle -> Bool Source # (/=) :: StringOutputStyle -> StringOutputStyle -> Bool Source #
type Rep StringOutputStyle Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

type Rep StringOutputStyle = D1 ('MetaData "StringOutputStyle" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "Literal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "EscapeNonPrintable" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DoNotEscapeNonPrintable" 'PrefixI 'False) (U1 :: Type -> Type)))

defaultOutputOptionsDarkBg :: OutputOptions Source #

Default values for `OutputOptions` when printing to a console with a dark background. `outputOptionsIndentAmount` is 4, and `outputOptionsColorOptions` is `defaultColorOptionsDarkBg`.

defaultOutputOptionsLightBg :: OutputOptions Source #

Default values for `OutputOptions` when printing to a console with a light background. `outputOptionsIndentAmount` is 4, and `outputOptionsColorOptions` is `defaultColorOptionsLightBg`.

defaultOutputOptionsNoColor :: OutputOptions Source #

Default values for `OutputOptions` when printing using using ANSI escape sequences for color. `outputOptionsIndentAmount` is 4, and `outputOptionsColorOptions` is `Nothing`.

data CheckColorTty Source #

Determines whether pretty-simple should check if the output `Handle` is a TTY device. Normally, users only want to print in color if the output `Handle` is a TTY device.

Constructors

CheckColorTty | Check if the output `Handle` is a TTY device. If the output `Handle` is a TTY device, determine whether to print in color based on `outputOptionsColorOptions`. If not, then set `outputOptionsColorOptions` to `Nothing` so the output does not get colorized.
NoCheckColorTty | Don't check if the output `Handle` is a TTY device. Determine whether to colorize the output based solely on the value of `outputOptionsColorOptions`.

#### Instances

Instances details

Generic CheckColorTty Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Printer

Associated Types

type Rep CheckColorTty |
Instance details Defined in Text.Pretty.Simple.Internal.Printer type Rep CheckColorTty = D1 ('MetaData "CheckColorTty" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "CheckColorTty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NoCheckColorTty" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: CheckColorTty -> Rep CheckColorTty x Source #

to :: Rep CheckColorTty x -> CheckColorTty Source #

Show CheckColorTty Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods showsPrec :: Int -> CheckColorTty -> ShowS Source # show :: CheckColorTty -> String Source # showList :: [CheckColorTty] -> ShowS Source #
Eq CheckColorTty Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer Methods (==) :: CheckColorTty -> CheckColorTty -> Bool Source # (/=) :: CheckColorTty -> CheckColorTty -> Bool Source #
type Rep CheckColorTty Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Printer type Rep CheckColorTty = D1 ('MetaData "CheckColorTty" "Text.Pretty.Simple.Internal.Printer" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "CheckColorTty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NoCheckColorTty" 'PrefixI 'False) (U1 :: Type -> Type))

# `ColorOptions`

defaultColorOptionsDarkBg :: ColorOptions Source #

Default color options for use on a dark background.

defaultColorOptionsLightBg :: ColorOptions Source #

Default color options for use on a light background.

data ColorOptions Source #

These options are for colorizing the output of functions like `pPrint`.

If you don't want to use a color for one of the options, use `colorNull`.

Constructors

ColorOptions |

Fields

- colorQuote :: Style

  Color to use for quote characters (`"`) around strings.

- colorString :: Style

  Color to use for strings.

- colorError :: Style

  Color for errors, e.g. unmatched brackets.

- colorNum :: Style

  Color to use for numbers.

- colorRainbowParens :: [Style]

  A list of colors to use for rainbow parenthesis output. Use '[]' if you don't want rainbow parenthesis. Use just a single item if you want all the rainbow parenthesis to be colored the same.

#### Instances

Instances details

Generic ColorOptions Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

Associated Types

type Rep ColorOptions |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

type Rep ColorOptions = D1 ('MetaData "ColorOptions" "Text.Pretty.Simple.Internal.Color" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "ColorOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "colorQuote") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: S1 ('MetaSel ('Just "colorString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style)) :*: (S1 ('MetaSel ('Just "colorError") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: (S1 ('MetaSel ('Just "colorNum") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: S1 ('MetaSel ('Just "colorRainbowParens") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Style])))))

Methods

from :: ColorOptions -> Rep ColorOptions x Source #

to :: Rep ColorOptions x -> ColorOptions Source #

Show ColorOptions Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Color Methods showsPrec :: Int -> ColorOptions -> ShowS Source # show :: ColorOptions -> String Source # showList :: [ColorOptions] -> ShowS Source #
Eq ColorOptions Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Color Methods (==) :: ColorOptions -> ColorOptions -> Bool Source # (/=) :: ColorOptions -> ColorOptions -> Bool Source #
type Rep ColorOptions Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

type Rep ColorOptions = D1 ('MetaData "ColorOptions" "Text.Pretty.Simple.Internal.Color" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "ColorOptions" 'PrefixI 'True) ((S1 ('MetaSel ('Just "colorQuote") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: S1 ('MetaSel ('Just "colorString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style)) :*: (S1 ('MetaSel ('Just "colorError") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: (S1 ('MetaSel ('Just "colorNum") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Style) :*: S1 ('MetaSel ('Just "colorRainbowParens") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Style])))))

data Style Source #

Ways to style terminal output.

Constructors

Style |

Fields

- styleColor :: Maybe (Color, Intensity)
- styleBold :: Bool
- styleItalic :: Bool
- styleUnderlined :: Bool

#### Instances

Instances details

Generic Style Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

Associated Types

type Rep Style |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

type Rep Style = D1 ('MetaData "Style" "Text.Pretty.Simple.Internal.Color" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "Style" 'PrefixI 'True) ((S1 ('MetaSel ('Just "styleColor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Color, Intensity))) :*: S1 ('MetaSel ('Just "styleBold") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "styleItalic") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "styleUnderlined") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

Methods

from :: Style -> Rep Style x Source #

to :: Rep Style x -> Style Source #

Show Style Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Color Methods showsPrec :: Int -> Style -> ShowS Source # show :: Style -> String Source # showList :: [Style] -> ShowS Source #
Eq Style Source # |
Instance details Defined in Text.Pretty.Simple.Internal.Color Methods (==) :: Style -> Style -> Bool Source # (/=) :: Style -> Style -> Bool Source #
type Rep Style Source # |

Instance details

Defined in Text.Pretty.Simple.Internal.Color

type Rep Style = D1 ('MetaData "Style" "Text.Pretty.Simple.Internal.Color" "pretty-simple-4.1.4.0-5LNLN3x68GgLenSG4gkeD6" 'False) (C1 ('MetaCons "Style" 'PrefixI 'True) ((S1 ('MetaSel ('Just "styleColor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Color, Intensity))) :*: S1 ('MetaSel ('Just "styleBold") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "styleItalic") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "styleUnderlined") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

data Color Source #

The 8 ANSI terminal colors.

Constructors

Black |
Red |
Green |
Yellow |
Blue |
Magenta |
Cyan |
White |

#### Instances

Instances details

Show Color |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods showsPrec :: Int -> Color -> ShowS Source # show :: Color -> String Source # showList :: [Color] -> ShowS Source #
Eq Color |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods (==) :: Color -> Color -> Bool Source # (/=) :: Color -> Color -> Bool Source #
Ord Color |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods compare :: Color -> Color -> Ordering Source # (<) :: Color -> Color -> Bool Source # (<=) :: Color -> Color -> Bool Source # (>) :: Color -> Color -> Bool Source # (>=) :: Color -> Color -> Bool Source # max :: Color -> Color -> Color Source # min :: Color -> Color -> Color Source #

data Intensity Source #

Dull or vivid coloring, as supported by ANSI terminals.

Constructors

Vivid |
Dull |

#### Instances

Instances details

Show Intensity |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods showsPrec :: Int -> Intensity -> ShowS Source # show :: Intensity -> String Source # showList :: [Intensity] -> ShowS Source #
Eq Intensity |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods (==) :: Intensity -> Intensity -> Bool Source # (/=) :: Intensity -> Intensity -> Bool Source #
Ord Intensity |

Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Methods

compare :: Intensity -> Intensity -> Ordering Source #

(<) :: Intensity -> Intensity -> Bool Source #

(<=) :: Intensity -> Intensity -> Bool Source #

(>) :: Intensity -> Intensity -> Bool Source #

(>=) :: Intensity -> Intensity -> Bool Source #

max :: Intensity -> Intensity -> Intensity Source #

min :: Intensity -> Intensity -> Intensity Source #

colorNull :: Style Source #

No styling.

# Examples

Here are some examples of using `pPrint` on different data types. You can look at these examples to get an idea of what `pPrint` will output.

Simple Haskell data type

    >>> data Foo a = Foo a String Char deriving Show

    >>> pPrint $ Foo 3 "hello" 'a'
    Foo 3 "hello" 'a'

List

    >>> pPrint $ [1,2,3]
    [ 1
    , 2
    , 3
    ]

Slightly more complicated list

    >>> pPrint $ [ Foo [ (), () ] "hello" 'b' ]
    [ Foo
        [ ()
        , ()
        ] "hello" 'b'
    ]

    >>> pPrint $ [ Foo [ "bar", "baz" ] "hello" 'a', Foo [] "bye" 'b' ]
    [ Foo
        [ "bar"
        , "baz"
        ] "hello" 'a'
    , Foo [] "bye" 'b'
    ]

Record

    >>> :{
    data Bar b = Bar
      { barInt :: Int
      , barA :: b
      , barList :: [Foo Double]
      } deriving Show
    :}

    >>> pPrint $ Bar 1 [10, 11] [Foo 1.1 "" 'a', Foo 2.2 "hello" 'b']
    Bar
        { barInt = 1
        , barA =
            [ 10
            , 11
            ]
        , barList =
            [ Foo 1.1 "" 'a'
            , Foo 2.2 "hello" 'b'
            ]
        }

Newtype

    >>> newtype Baz = Baz { unBaz :: [String] } deriving Show

    >>> pPrint $ Baz ["hello", "bye"]
    Baz
        { unBaz =
            [ "hello"
            , "bye"
            ]
        }

Newline Rules

    >>> data Foo = A | B Foo | C [Foo] [Foo] deriving Show

    >>> pPrint $ B ( B A )
    B ( B A )

    >>> pPrint $ B ( B ( B A ) )
    B
        ( B ( B A ) )

    >>> pPrint $ B ( B ( B ( B A ) ) )
    B
        ( B
            ( B ( B A ) )
        )

    >>> pPrint $ B ( C [A, A] [B A, B (B (B A))] )
    B
        ( C
            [ A
            , A
            ]
            [ B A
            , B
                ( B ( B A ) )
            ]
        )

Laziness

    >>> take 100 . unpack . pShowNoColor $ [1..]
    "[ 1\n, 2\n, 3\n, 4\n, 5\n, 6\n, 7\n, 8\n, 9\n, 10\n, 11\n, 12\n, 13\n, 14\n, 15\n, 16\n, 17\n, 18\n, 19\n, 20\n, 21\n, 22"

Unicode

    >>> pPrint $ Baz ["猫", "犬", "ヤギ"]
    Baz
        { unBaz =
            [ "猫"
            , "犬"
            , "ヤギ"
            ]
        }

Char

    >>> pPrint 'λ'
    'λ'

Compactness options

    >>> pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} "AST [] [Def ((3,1),(5,30)) (Id \"fact'\" \"fact'\") [] (Forall ((3,9),(3,26)) [((Id \"n\" \"n_0\"),KPromote (TyCon (Id \"Nat\" \"Nat\")))])]"
    AST []
        [ Def
            ( ( 3, 1 ), ( 5, 30 ) )
            ( Id "fact'" "fact'" ) []
            ( Forall
                ( ( 3, 9 ), ( 3, 26 ) )
                [ ( ( Id "n" "n_0" ), KPromote ( TyCon ( Id "Nat" "Nat" ) ) ) ]
            )
        ]

    >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompactParens = True} $ B ( C [A, A] [B A, B (B (B A))] )
    B
        ( C
            [ A
            , A ]
            [ B A
            , B
                ( B ( B A ) ) ] )

    >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ [("id", 123), ("state", 1), ("pass", 1), ("tested", 100), ("time", 12345)]
    [
        ( "id", 123 ),
        ( "state", 1 ),
        ( "pass", 1 ),
        ( "tested", 100 ),
        ( "time", 12345 )
    ]

Initial indent

    >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsInitialIndent = 3} $ B ( B ( B ( B A ) ) )
       B
           ( B
               ( B ( B A ) )
           )

Weird/illegal show instances

    >>> pPrintString "2019-02-18 20:56:24.265489 UTC"
    2019-02-18 20:56:24.265489 UTC

    >>> pPrintString "a7ed86f7-7f2c-4be5-a760-46a3950c2abf"
    a7ed86f7-7f2c-4be5-a760-46a3950c2abf

    >>> pPrintString "192.168.0.1:8000"
    192.168.0.1:8000

    >>> pPrintString "A @\"type\" 1"
    A @"type" 1

    >>> pPrintString "2+2"
    2+2

    >>> pPrintString "1.0e-2"
    1.0e-2

    >>> pPrintString "0x1b"
    0x1b

Other

Making sure the spacing after a string is correct.

    >>> data Foo = Foo String Int deriving Show

    >>> pPrint $ Foo "bar" 0
    Foo "bar" 0

Non-printable characters will get escaped.

    >>> pPrint "this string has non-printable characters: \x8 and \x9"
    "this string has non-printable characters: \x8 and \x9"

If you don't want non-printable characters to be escaped, take a look at `outputOptionsStringStyle` and `StringOutputStyle`.