| Copyright | (c) Dennis Gosnell 2016 |
|---|---|
| License | BSD-style (see LICENSE file) |
| Maintainer | [email protected] |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.Pretty.Simple
Description
This module contains the functions pPrint, pShow, and pString, for
pretty-printing any Haskell data type with a show instance.
pPrint should be the main go-to function when debugging in GHCi.
There are other variations of pPrint, pShow, and pString for printing
without color and changing the indentation amount. Most users can ignore these.
See the Examples section at the end of this module for examples of acutally
using pPrint.
- pShow :: Show a => a -> Text
- pPrint :: (MonadIO m, Show a) => a -> m ()
- pString :: String -> Text
- pShowNoColor :: Show a => a -> Text
- pPrintNoColor :: (MonadIO m, Show a) => a -> m ()
- pStringNoColor :: String -> Text
- pShowOpt :: Show a => OutputOptions -> a -> Text
- pPrintOpt :: (MonadIO m, Show a) => OutputOptions -> a -> m ()
- pStringOpt :: OutputOptions -> String -> Text
- data OutputOptions = OutputOptions {}
- data UseColor
- defaultOutputOptions :: OutputOptions
- noColorOutputOptions :: OutputOptions
Output With Color
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" ]
Output With Output Options
pShowOpt :: Show a => OutputOptions -> a -> Text Source #
Like pShow but takes OutputOptions to change how the
pretty-printing is done.
pPrintOpt :: (MonadIO m, Show a) => 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 noColorOutputOptions $ Just ("hello", "bye")Just ( "hello" , "bye" )
This is what smaller indentation looks like:
>>>let smallIndent = noColorOutputOptions {outputOptionsIndentAmount = 1}>>>pPrintOpt smallIndent $ Just ("hello", "bye")Just ( "hello" , "bye" )
pStringOpt :: OutputOptions -> String -> Text Source #
Like pString but takes OutputOptions to change how the
pretty-printing is done.
data OutputOptions Source #
Data-type wrapping up all the options available when rendering the list
of Outputs.
Constructors
| OutputOptions | |
Fields
| |
Instances
defaultOutputOptions :: OutputOptions Source #
Default values for OutputOptions. outputOptionsIndentAmount defaults
to 4, and outputOptionsUseColor defaults to UseColor.
noColorOutputOptions :: OutputOptions Source #
noColorOutputOptions is just like defaultOutputOptions, but
outputOptionsUseColor is set to NoColor.
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.
The following examples are all using pPrintNoColor instead of pPrint
because their output is being checked using
doctest. pPrint outputs ANSI
escape codes in order to produce color, so the following examples would be
hard to read had pPrint been used.
Simple Haskell data type
>>>data Foo a = Foo a String deriving Show
>>>pPrintNoColor $ Foo 3 "hello"Foo 3 "hello"
List
>>>pPrintNoColor $ [1,2,3][ 1 , 2 , 3 ]
Slightly more complicated list
>>>pPrintNoColor $ [ Foo [ (), () ] "hello" ][ Foo [ () , () ] "hello" ]
>>>pPrintNoColor $ [ Foo [ "bar", "baz" ] "hello", Foo [] "bye" ][ Foo [ "bar" , "baz" ] "hello" , Foo [] "bye" ]
Record
>>>:{data Bar b = Bar { barInt :: Int , barA :: b , barList :: [Foo Double] } deriving Show :}
>>>pPrintNoColor $ Bar 1 [10, 11] [Foo 1.1 "", Foo 2.2 "hello"]Bar { barInt = 1 , barA = [ 10 , 11 ] , barList = [ Foo 1.1 "" , Foo 2.2 "hello" ] }
Newtype
>>>newtype Baz = Baz { unBaz :: [String] } deriving Show
>>>pPrintNoColor $ Baz ["hello", "bye"]Baz { unBaz = [ "hello" , "bye" ] }