pretty-simple-4.1.4.0/ 0000755 0000000 0000000 00000000000 07346545000 012665 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/CHANGELOG.md 0000644 0000000 0000000 00000020037 07346545000 014500 0 ustar 00 0000000 0000000 ## 4.1.4.0
* Fix double-quoting issue with `pTraceShowWith`.
[#132](https://github.com/cdepillabout/pretty-simple/pull/132)
Thanks [@leoslf](https://github.com/leoslf)!
## 4.1.3.0
* Remove custom setup. This makes cross-compiling `pretty-simple` a lot more
straightforward. No functionality has been lost from the library, since the
custom setup was only used for generating tests.
[#107](https://github.com/cdepillabout/pretty-simple/pull/107)
## 4.1.2.0
* Fix a problem with the `pHPrint` function incorrectly
outputting a trailing newline to stdout, instead of the
handle you pass it.
[#118](https://github.com/cdepillabout/pretty-simple/pull/118)
* Add a [web app](https://cdepillabout.github.io/pretty-simple/) where you
can play around with `pretty-simple` in your browser.
[#116](https://github.com/cdepillabout/pretty-simple/pull/116).
This took a lot of hard work by [@georgefst](https://github.com/georgefst)!
## 4.1.1.0
* Make the pretty-printed output with `outputOptionsCompact` enabled a little
more compact.
[#110](https://github.com/cdepillabout/pretty-simple/pull/110).
Thanks [@juhp](https://github.com/juhp)!
* Add a `--compact` / `-C` flag to the `pretty-simple` executable that enables
`outputOptionsCompact`.
[#111](https://github.com/cdepillabout/pretty-simple/pull/111).
Thanks again @juhp!
* Add `pTraceWith` and `pTraceShowWith` to `Debug.Pretty.Simple`.
[#104](https://github.com/cdepillabout/pretty-simple/pull/104).
Thanks [@LeviButcher](https://github.com/LeviButcher)!
## 4.1.0.0
* Fix a regression which arose in 4.0, whereby excess spaces would be inserted for unusual strings like dates and IP addresses.
[#105](https://github.com/cdepillabout/pretty-simple/pull/105)
* Attach warnings to debugging functions, so that they're easy to find and remove.
[#103](https://github.com/cdepillabout/pretty-simple/pull/103)
* Some minor improvements to the CLI tool:
* Add a `--version`/`-v` flag.
[#83](https://github.com/cdepillabout/pretty-simple/pull/83)
* Add a trailing newline.
[#87](https://github.com/cdepillabout/pretty-simple/pull/87)
* Install by default, without requiring a flag.
[#94](https://github.com/cdepillabout/pretty-simple/pull/94)
## 4.0.0.0
* Expand `OutputOptions`:
* Compactness, including grouping of parentheses.
[#72](https://github.com/cdepillabout/pretty-simple/pull/72)
* Page width, affecting when lines are grouped if compact output is enabled.
[#72](https://github.com/cdepillabout/pretty-simple/pull/72)
* Indent whole expression. Useful when using `pretty-simple` for one part
of a larger output.
[#71](https://github.com/cdepillabout/pretty-simple/pull/71)
* Use `Style` type for easier configuration of colour, boldness etc.
[#73](https://github.com/cdepillabout/pretty-simple/pull/73)
* Significant internal rewrite of printing code, to make use of the [prettyprinter](https://hackage.haskell.org/package/prettyprinter)
library. The internal function `layoutString` can be used to integrate with
other `prettyprinter` backends, such as [prettyprinter-lucid](https://hackage.haskell.org/package/prettyprinter-lucid)
for HTML output.
[#67](https://github.com/cdepillabout/pretty-simple/pull/67)
## 3.3.0.0
* Add an output option to print escaped and non-printable characters
literally when outputting strings.
[#68](https://github.com/cdepillabout/pretty-simple/pull/68) and
[#69](https://github.com/cdepillabout/pretty-simple/pull/69)
Thanks Joe Hermaszewski ([@expipiplus1](https://github.com/expipiplus1))!
## 3.2.3.0
* Fix a bug that messes up printing identifiers with `'` in the name.
Now identifiers like `data Don't = Don't` show up properly.
[#65](https://github.com/cdepillabout/pretty-simple/pull/65)
Thanks George Thomas ([@georgefst](https://github.com/georgefst))!
## 3.2.2.0
* Remove whitespace from the ends of lines.
[#62](https://github.com/cdepillabout/pretty-simple/pull/62)
Thanks Gaith Hallak ([@ghallak](https://github.com/ghallak))!
## 3.2.1.0
* Added `pTraceOpt` functions to `Debug.Pretty.Simple`.
[#58](https://github.com/cdepillabout/pretty-simple/pull/58)
Thanks again [sureyeaah](https://github.com/sureyeaah)!
## 3.2.0.0
* Add support for pretty-printing Haskell character literals.
[#57](https://github.com/cdepillabout/pretty-simple/pull/57)
Thanks again [sjakobi](https://github.com/sjakobi)!
## 3.1.1.0
* Added a `pPrintString` function for pretty-printing a `String` that is the
output of `show`. Implemented in
[#54](https://github.com/cdepillabout/pretty-simple/pull/54). Thanks
[sureyeaah](https://github.com/sureyeaah)!
* Fix build on GHC-7.10.3.
[#55](https://github.com/cdepillabout/pretty-simple/pull/55). Thanks
[sjakobi](https://github.com/sjakobi).
## 3.1.0.0
* Numbers are now highlighted in green by default. Implemented in
[#51](https://github.com/cdepillabout/pretty-simple/pull/51).
Thanks [lawrencebell](https://github.com/lawrencebell)!
## 3.0.0.0
* pretty-simple now escapes non-printable characters by default. A field
called `outputOptionsEscapeNonPrintable` has been added to `OutputOptions`
to control this behavior. Implemented in
[#44](https://github.com/cdepillabout/pretty-simple/pull/44). Thanks
[dminuoso](https://github.com/dminuoso)!
* pretty-simple now checks the output `Handle` to determine whether to print
in color when using functions like `pPrint`. This makes it so that you
can redirect output to a file on disk and still be able to read the
output from `pPrint`! Implemented in
[#47](https://github.com/cdepillabout/pretty-simple/pull/47). Thanks
[metiulekm](https://github.com/metiulekm)!
* Add functions like `pHPrint` for specifying the `Handle` to output to.
Added in [#47](https://github.com/cdepillabout/pretty-simple/pull/47).
## 2.2.0.1
* Fixed a [bug](https://github.com/cdepillabout/pretty-simple/pull/41) where
the parser failed to parse escaped quotation marks in string literals.
Thanks [Andreas](https://github.com/anka-213)!
## 2.2.0.0
* Fixed a [bug](https://github.com/cdepillabout/pretty-simple/pull/33) with a
missing space after strings. Thanks again
[Andrew](https://github.com/andrew-lei)!
* Add a command line flag `--color` to be able to set whether to use colors for
a dark background (`--color dark-bg`), a light background (`--color light-bg`),
or no color (`--color no-color`). This is from
[great work](https://github.com/cdepillabout/pretty-simple/pull/35) by
[Andrew](https://github.com/andrew-lei)!
* Made parsing/printing lazy - pretty-printing will now output strings continuously
as they're read, handling potentially infinite input.
## 2.1.0.1
* Fix a [bug](https://github.com/cdepillabout/pretty-simple/pull/32) where
printing deeply nested data structures would take exponential time. Thanks
[Andrew](https://github.com/andrew-lei)!
## 2.1.0.0
* Make strings have indentation by default when pretty-printed. See
[#26](https://github.com/cdepillabout/pretty-simple/pull/26). Thanks
[Milan](https://github.com/Wizek)!
## 2.0.2.1
* Add a small command-line program that will pretty print anything from stdin
called `pretty-print`. It can be installed to `~/.local/bin` if you enable
the flag `buildexe` like so:
```sh
$ stack install pretty-simple-2.0.2.1 --flag pretty-simple:buildexe
```
When you run it, you can paste something you want formatted on stdin, then
press Ctrl-D. It will print the formatted version on
stdout:
```sh
$ pretty-simple
[(Just 3, Just 4)]
^D
[
( Just 3
, Just 4
)
]
```
## 2.0.2.0
* Fix a [problem](https://github.com/cdepillabout/pretty-simple/pull/20) with
the pTraceShow functions not working correctly.
## 2.0.1.0
* Added the `Debug.Pretty.Simple` that exports functions that work like
`Debug.Trace`.
pretty-simple-4.1.4.0/LICENSE 0000644 0000000 0000000 00000002767 07346545000 013706 0 ustar 00 0000000 0000000 Copyright Dennis Gosnell (c) 2016
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pretty-simple-4.1.4.0/README.md 0000644 0000000 0000000 00000017053 07346545000 014152 0 ustar 00 0000000 0000000
Text.Pretty.Simple
==================
[](https://github.com/cdepillabout/pretty-simple/actions)
[](https://hackage.haskell.org/package/pretty-simple)
[](http://stackage.org/lts/package/pretty-simple)
[](http://stackage.org/nightly/package/pretty-simple)

`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:
```haskell
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:
```haskell
> print bar
Bar {bar1 = 10.55, bar2 = [Foo {foo1 = 3, foo2 = ["hello","goodbye"]},Foo {foo1 = 3, foo2 = ["hello","goodbye"]}]}
```
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:

## Usage
`pretty-simple` can be easily used from `ghci` when debugging.
When using `stack` to run `ghci`, just append the `--package` flag to
the command line to load `pretty-simple`:
```sh
$ stack ghci --package pretty-simple
```
Or, with cabal:
```sh
$ cabal repl --build-depends pretty-simple
```
Once you get a prompt in `ghci`, you can use `import` to get `pretty-simple`'s
[`pPrint`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pPrint)
function in scope.
```haskell
> import Text.Pretty.Simple (pPrint)
```
You can test out `pPrint` with simple data types like `Maybe` or tuples.
```haskell
> pPrint $ Just ("hello", "goodbye")
Just
( "hello"
, "goodbye"
)
```
If for whatever reason you're not able to incur a dependency on the `pretty-simple` library, you can simulate its behaviour by using `process` to call out to the command line executable (see below for installation):
```hs
pPrint :: Show a => a -> IO ()
pPrint = putStrLn <=< readProcess "pretty-simple" [] . show
```
There's also a [web app](https://cdepillabout.github.io/pretty-simple), compiled with GHCJS, where you can play around with `pretty-simple` in your browser.
## 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`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pPrintNoColor)
function.
- Rainbow Parentheses
- Easy to understand deeply nested data types.
- Configurable
- Indentation, compactness, colors and more are configurable with the
[`pPrintOpt`](https://hackage.haskell.org/package/pretty-simple-1.0.0.6/docs/Text-Pretty-Simple.html#v:pPrintOpt)
function.
- Fast
- No problem pretty-printing 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.
## Other Uses
### Pretty-print all GHCi output
The `pPrint` function can be used as the default output function in GHCi.
All you need to do is run GHCi with a command like one of these:
```sh
$ stack ghci --ghci-options "-interactive-print=Text.Pretty.Simple.pPrint" --package pretty-simple
```
```sh
$ cabal repl --repl-options "-interactive-print=Text.Pretty.Simple.pPrint" --build-depends pretty-simple
```
Now, whenever you make GHCi evaluate an expression, GHCi will pretty-print the
result using `pPrint`! See
[here](https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/ghci.html#using-a-custom-interactive-printing-function)
for more info on this neat feature in GHCi.
### Pretty-printing JSON
`pretty-simple` can be used to pretty-print any `String` that is similar to
Haskell data types. The only requirement is that the `String` must correctly
use brackets, parenthese, and braces to indicate nesting.
For example, the
[`pString`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pString)
function can be used to pretty-print JSON.
Recall our example from before.
```haskell
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]
```
You can use [`aeson`](https://hackage.haskell.org/package/aeson) to turn these
data types into JSON. First, you must derive
[`ToJSON`](https://hackage.haskell.org/package/aeson/docs/Data-Aeson.html#t:ToJSON)
instances for the data types. It is easiest to do this with Template Haskell:
```haskell
{-# LANGUAGE TemplateHaskell #-}
$(deriveJSON defaultOptions ''Foo)
$(deriveJSON defaultOptions ''Bar)
```
If you run this in `ghci` and type `encode bar`, you'll get output like this:
```haskell
> import Data.Aeson (encode)
> putLazyByteStringLn $ encode bar
{"bar1":10.55,"bar2":[{"foo1":3,"foo2":["hello","goodbye"]},{"foo1":3,"foo2":["hello","goodbye"]}]}
```
Just like Haskell's normal `print` output, this is pretty hard to read.
`pretty-simple` can be used to pretty-print the JSON-encoded `bar` in an
easy-to-read format:

(You can find the `lazyByteStringToString`, `putLazyByteStringLn`,
and `putLazyTextLn` in the [`ExampleJSON.hs`](example/ExampleJSON.hs)
file.)
### Pretty-printing from the command line
`pretty-simple` includes a command line executable that can be used to
pretty-print anything passed in on stdin.
It can be installed to `~/.local/bin/` with the following command.
```sh
$ stack install pretty-simple
```
When run on the command line, you can paste in the Haskell datatype you want to
be formatted, then hit Ctrl-D:

This is very useful if you accidentally print out a Haskell data type with
`print` instead of `pPrint`.
## Contributions
Feel free to open an
[issue](https://github.com/cdepillabout/pretty-simple/issues) or
[PR](https://github.com/cdepillabout/pretty-simple/pulls) for any
bugs/problems/suggestions/improvements.
### Testing
To run the test suite locally, one must install the executables `doctest` and
`cabal-doctest`, e.g. with
`cabal install --ignore-project doctest --flag cabal-doctest`.
Then run the command `cabal doctest`.
## Maintainers
- [@cdepillabout](https://github.com/cdepillabout)
- [@georgefst](https://github.com/georgefst)
pretty-simple-4.1.4.0/app/ 0000755 0000000 0000000 00000000000 07346545000 013445 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/app/Main.hs 0000644 0000000 0000000 00000005237 07346545000 014674 0 ustar 00 0000000 0000000 module Main where
-- This is a small executable that will pretty-print anything from stdin.
-- It can be installed to `~/.local/bin` if you enable the flag `buildexe` like so:
--
-- @
-- $ stack install pretty-simple-2.0.1.1 --flag pretty-simple:buildexe
-- @
--
-- When you run it, you can paste something you want formatted on stdin, then
-- press @Ctrl-D@. It will print the formatted version on stdout:
--
-- @
-- $ pretty-simple
-- [(Just 3, Just 4)]
--
-- ^D
--
-- [
-- ( Just 3
-- , Just 4
-- )
-- ]
-- @
import Data.Monoid ((<>))
import Data.Text (unpack)
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy.IO as LT
import Data.Version (showVersion)
import Options.Applicative
( Parser, ReadM, execParser, fullDesc, help, helper, info, infoOption
, long, option, progDesc, readerError, short, showDefaultWith, str
, switch, value)
import Paths_pretty_simple (version)
import Text.Pretty.Simple
( pStringOpt, OutputOptions
, defaultOutputOptionsDarkBg
, defaultOutputOptionsLightBg
, defaultOutputOptionsNoColor
, outputOptionsCompact
)
data Color = DarkBg
| LightBg
| NoColor
data Args = Args
{ color :: Color
, compact :: Bool
}
colorReader :: ReadM Color
colorReader = do
string <- str
case string of
"dark-bg" -> pure DarkBg
"light-bg" -> pure LightBg
"no-color" -> pure NoColor
x -> readerError $ "Could not parse " <> x <> " as a color."
args :: Parser Args
args = Args
<$> option colorReader
( long "color"
<> short 'c'
<> help "Select printing color. Available options: dark-bg (default), light-bg, no-color."
<> showDefaultWith (const "dark-bg")
<> value DarkBg
)
<*> switch
( long "compact"
<> short 'C'
<> help "Compact output"
)
versionOption :: Parser (a -> a)
versionOption =
infoOption
(showVersion version)
( long "version"
<> short 'V'
<> help "Show version"
)
main :: IO ()
main = do
args' <- execParser opts
input <- T.getContents
let output = pStringOpt (getPrintOpt args') $ unpack input
LT.putStrLn output
where
opts = info (helper <*> versionOption <*> args)
( fullDesc
<> progDesc "Format Haskell data types with indentation and highlighting"
)
getPrintOpt :: Args -> OutputOptions
getPrintOpt as =
(getColorOpt (color as)) {outputOptionsCompact = compact as}
getColorOpt :: Color -> OutputOptions
getColorOpt DarkBg = defaultOutputOptionsDarkBg
getColorOpt LightBg = defaultOutputOptionsLightBg
getColorOpt NoColor = defaultOutputOptionsNoColor
pretty-simple-4.1.4.0/bench/ 0000755 0000000 0000000 00000000000 07346545000 013744 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/bench/Bench.hs 0000644 0000000 0000000 00000002105 07346545000 015315 0 ustar 00 0000000 0000000
module Main where
import Data.Monoid ((<>))
import Data.Text.Lazy (Text)
import Criterion.Main (Benchmark, bench, bgroup, defaultMain, nf)
import Text.Pretty.Simple (pShow)
import Example.Data (foo, bar, baz)
main :: IO ()
main =
defaultMain
[ bgroup
"pShow"
[ bench "Foo" $ nf pShow foo
, bench "Bar" $ nf pShow bar
, bench "Baz" $ nf pShow baz
]
, bgroup "recursive deeply-nested data structure" (fmap nestTest [22..25])
]
data ExampleExpr
= A
| B ExampleExpr
| C [ExampleExpr]
deriving (Show)
nest :: ExampleExpr -> Int -> ExampleExpr
nest expr 0 = expr
nest expr n = nest (B expr) (n - 1)
-- | There was a bug in the pretty-simple code that caused deeply nested data
-- structures to have an exponential runtime. Effectively, the runtime doubled
-- at level. The following benchmark is to make sure that we don't
-- accidentally introduce this exponential runtime again.
nestTest :: Int -> Benchmark
nestTest n = bench ("level " <> show n) $ nf test n
where
test :: Int -> Text
test = pShow . nest (C [A,A])
pretty-simple-4.1.4.0/example/ 0000755 0000000 0000000 00000000000 07346545000 014320 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/example/Example.hs 0000644 0000000 0000000 00000001037 07346545000 016250 0 ustar 00 0000000 0000000
{- |
Copyright : Dennis Gosnell 2017
License : BSD3
Maintainer : Dennis Gosnell (cdep.illabout@gmail.com)
Stability : experimental
Portability : unknown
This is an short example of using 'pPrint' from "Text.Pretty.Simple" to
pretty-print a Haskell data type.
-}
module Main where
import Text.Pretty.Simple (pPrint)
import Example.Data (bar)
main :: IO ()
main = do
putStrLn "\nThe following normal \"print\" output:\n"
print bar
putStrLn "\ngets turned into this (using \"Text.Pretty.Simple.pPrint\"):\n"
pPrint bar
pretty-simple-4.1.4.0/example/Example/ 0000755 0000000 0000000 00000000000 07346545000 015713 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/example/Example/Data.hs 0000644 0000000 0000000 00000002443 07346545000 017123 0 ustar 00 0000000 0000000 {-# LANGUAGE DeriveDataTypeable #-}
{- |
Module : Example.Data
Copyright : Dennis Gosnell 2017
License : BSD3
Maintainer : Dennis Gosnell (cdep.illabout@gmail.com)
Stability : experimental
Portability : unknown
This module contains some data types and values that users can use to play
around with pretty-simple.
These data types are also use in the two example programs, as well as the
benchmark for pretty-simple.
Most users should use 'foo' or 'bar'. 'baz' is an extremely large data type,
only used in the benchmark.
-}
module Example.Data where
import Data.Data (Data)
import Data.Typeable (Typeable)
data Foo = Foo
{ foo1 :: Integer
, foo2 :: [String]
, foo3 :: Double
} deriving (Data, Eq, Read, Show, Typeable)
data Bar = Bar
{ bar1 :: Integer
, bar2 :: [Foo]
, bar3 :: Double
} deriving (Data, Eq, Read, Show, Typeable)
data Baz = Baz
{ baz1 :: Bar
, baz2 :: [Baz]
} deriving (Data, Eq, Read, Show, Typeable)
foo :: Foo
foo = Foo 3 fooList 3.3
bar :: Bar
bar = Bar 10 (replicate 1 foo) 10.55
bazLevel1 :: Baz
bazLevel1 = Baz bar []
bazLevel2 :: Baz
bazLevel2 = Baz bar $ replicate 50 bazLevel1
baz :: Baz
baz = Baz bar $ replicate 30 bazLevel2
fooList :: [String]
fooList =
[ "hello"
, "goodbye"
, "dog"
, "cat"
, "fox"
, "beaver"
]
pretty-simple-4.1.4.0/example/ExampleJSON.hs 0000644 0000000 0000000 00000003525 07346545000 016746 0 ustar 00 0000000 0000000 {-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{- |
Copyright : Dennis Gosnell 2017
License : BSD3
Maintainer : Dennis Gosnell (cdep.illabout@gmail.com)
Stability : experimental
Portability : unknown
This is an short example of using 'pString' from "Text.Pretty.Simple" to
pretty-print JSON.
-}
module Main where
import Data.Aeson (encode)
import Data.Aeson.TH (defaultOptions, deriveJSON)
import qualified Data.ByteString.Lazy as LByteString (ByteString, toStrict)
import Data.Text as Text (Text, unpack)
import Data.Text.Encoding (decodeUtf8)
import qualified Data.Text.IO as TextIO (putStrLn)
import qualified Data.Text.Lazy as LText (Text)
import qualified Data.Text.Lazy.IO as LTextIO (putStrLn)
import Text.Pretty.Simple (pString)
import Example.Data (Foo, Bar, bar)
$(deriveJSON defaultOptions ''Foo)
$(deriveJSON defaultOptions ''Bar)
main :: IO ()
main = do
putStrLn "\nThe following normal \"Data.Aeson.encode\" output:\n"
putLazyByteStringLn $ encode bar
putStrLn "\ngets turned into this (using \"Text.Pretty.Simple.pString\"):\n"
LTextIO.putStrLn . pString . lazyByteStringToString $ encode bar
-- | Convert a 'LByteString.ByteString' to a 'Text.Text' by utf8-encoding it.
lazyByteStringToText :: LByteString.ByteString -> Text.Text
lazyByteStringToText = decodeUtf8 . LByteString.toStrict
-- | Convert a 'LByteString.ByteString' to a 'String' by utf8-encoding it.
lazyByteStringToString :: LByteString.ByteString -> String
lazyByteStringToString = unpack . lazyByteStringToText
-- | Print a 'LByteString.ByteString' to the screen. Similar to 'putStrLn'.
putLazyByteStringLn :: LByteString.ByteString -> IO ()
putLazyByteStringLn = TextIO.putStrLn . lazyByteStringToText
-- | Print a 'LText.Text' to the screen. Similar to 'putStrLn'.
putLazyTextLn :: LText.Text -> IO ()
putLazyTextLn = LTextIO.putStrLn
pretty-simple-4.1.4.0/img/ 0000755 0000000 0000000 00000000000 07346545000 013441 5 ustar 00 0000000 0000000 pretty-simple-4.1.4.0/img/pretty-simple-example-screenshot.png 0000644 0000000 0000000 00000035727 07346545000 022607 0 ustar 00 0000000 0000000 PNG
IHDR R -Rr bKGD pHYs tIME IDATxwx&l@ҤwTG}ņ Ղ`9*xP,@Q*"R
@ @@ FzydBP6s]{}2;p癲3""Rb.TDDA*" TDDA*" TDDA*" -[$&6%j3~XȄI(ٺ7͟[imxbb8yfi{ӲUK&NyZ>+1Q~Mm}"D֯K^y
`O]HَH/m݊gȰqwwT&55eKWGw{ED*]gФic^yu:k7DOѶLcF1nX+eo|c2
8Ly4bbo>,\%mѮ]/=p|HCC[ŽO"<-} [K:|C_'&6; ЧooxKeɲEl}Ai6
Ͽ,?X̶ٰgf&wRs>|ݍF!LBC[W؊
moΤi?jC/.믥IƘf|ӷ7s>zzweg"ՍQ1d`f;vn5b0^F9=:1QFLl1 F݀F@@1FLlm[jio[cW
WWW