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

[ bsd3, library, text ] [ Propose Tags ]

Please see README.md


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.2.0.0, 0.3.0.0, 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.0.3, 1.0.0.4, 1.0.0.5, 1.0.0.6, 1.1.0.0, 1.1.0.1, 1.1.0.2, 1.1.0.3, 2.0.0.0, 2.0.1.0, 2.0.2.0, 2.0.2.1, 2.1.0.0, 2.1.0.1, 2.2.0.0, 2.2.0.1, 3.0.0.0, 3.1.0.0
Dependencies ansi-terminal (>=0.6), base (>=4.8 && <5), containers (>=0.5), lens (>=4.13), mono-traversable (>=0.10), mtl (>=2.2), parsec (>=3.1), pretty-simple, semigroups (>=0.18), text (>=1.2), transformers (>=0.4) [details]
License BSD-3-Clause
Copyright 2017 Dennis Gosnell
Author Dennis Gosnell
Maintainer cdep.illabout@gmail.com
Category Text
Home page https://github.com/cdepillabout/pretty-simple
Source repo head: git clone git@github.com:cdepillabout/pretty-simple.git
Uploaded by cdepillabout at Sun Jan 15 22:39:36 UTC 2017
Distributions Debian:2.1.0.1, LTSHaskell:2.2.0.1, NixOS:3.1.0.0, Stackage:2.2.0.1
Executables pretty-simple-example
Downloads 7377 total (411 in the last 30 days)
Rating 2.5 (votes: 4) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-01-15 [all 1 reports]

Modules

[Index]

Flags

NameDescriptionDefaultType
buildexample

Build a small example program showing how to use the pPrint function

DisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for pretty-simple-1.0.0.6

[back to package description]

Text.Pretty.Simple

Build Status Hackage Stackage LTS Stackage Nightly BSD3 license

pretty-simple is a pretty printer for Haskell data types that have a Show instance.

For example, imagine the following Haskell data types and values:

data Foo = Foo { foo1 :: Integer , foo2 :: [String] } deriving Show

foo :: Foo
foo = Foo 3 ["hello", "goodbye"]

data Bar = Bar { bar1 :: Double , bar2 :: [Foo] } deriving Show

bar :: Bar
bar = Bar 10.55 [foo, foo]

If you run this in ghci and type print bar, you'll get output like this:

Bar {bar1 = 10, bar2 = [Foo {foo1 = 3, foo2 = ["hello","goodbye"], foo3 = 3.3},Foo {foo1 = 3, foo2 = ["hello","goodbye"], foo3 = 3.3}], bar3 = 10.55}

This is pretty hard to read. Imagine if there were more fields or it were even more deeply nested. It would be even more difficult to read.

pretty-simple can be used to print bar in an easy-to-read format:

example screenshot

Usage

pretty-simple can be easily used from ghci when debugging.

When using stack to run ghci, just append append the --package flag to the command line to load pretty-simple.

$ stack ghci --package pretty-simple

Once you get a prompt in ghci, you can use import to get pretty-simple's pPrint function in scope.

> import Text.Pretty.Simple (pPrint)

You can test out pPrint with simple data types like Maybe or tuples.

> pPrint $ Just ("hello", "goodbye")
Just
    ( "hello"
    , "goodbye"
    )

Features

pretty-simple has these features:

  • Easy-to-read
    • Complex data types are simple to understand.
  • Color
    • Prints in color using ANSI escape codes.
    • It is possible to print without color by using the pPrintNoColor function.
  • Rainbox Parentheses
    • Easy to understand deeply nested data types.
  • Configurable Indentation
    • Amount of indentation is configurable with the pPrintOpt function.
  • Fast
    • No problem with data types thousands of lines long.
  • Works with any data type with a Show instance
    • Some common Haskell data types have a Show instance that produces non-valid Haskell code. pretty-simple will pretty-print even these data types.

Why not (some other package)?

Other pretty-printing packages have some combination of these defects:

  • No options for printing in color.
  • No options for changing the amount of indentation
  • Requires every data type to be an instance of some special typeclass (instead of just Show).
  • Requires all Show instances to output valid Haskell code.

Contributions

Feel free to open an issue or PR for any bugs/problems/suggestions/improvements.