{"id":13681486,"url":"https://github.com/cdepillabout/pretty-simple","last_synced_at":"2025-05-15T04:07:25.646Z","repository":{"id":14423664,"uuid":"76529173","full_name":"cdepillabout/pretty-simple","owner":"cdepillabout","description":"pretty-printer for Haskell data types that have a Show instance","archived":false,"fork":false,"pushed_at":"2025-01-27T13:44:33.000Z","size":1745,"stargazers_count":247,"open_issues_count":17,"forks_count":30,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-03T06:47:47.529Z","etag":null,"topics":["ghci","hacktoberfest","haskell","pretty-print","pretty-simple"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/pretty-simple","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdepillabout.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["cdepillabout"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-12-15T06:07:56.000Z","updated_at":"2025-04-19T12:35:45.000Z","dependencies_parsed_at":"2023-01-13T17:56:27.360Z","dependency_job_id":"8cc2195b-115d-4e45-8457-6855bb43f4a1","html_url":"https://github.com/cdepillabout/pretty-simple","commit_stats":{"total_commits":296,"total_committers":23,"mean_commits":"12.869565217391305","dds":"0.43918918918918914","last_synced_commit":"ff8294ea0efff24da6694792d7d40757ac59ae23"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fpretty-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fpretty-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fpretty-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fpretty-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdepillabout","download_url":"https://codeload.github.com/cdepillabout/pretty-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843693,"owners_count":21972947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ghci","hacktoberfest","haskell","pretty-print","pretty-simple"],"created_at":"2024-08-02T13:01:31.397Z","updated_at":"2025-05-15T04:07:20.634Z","avatar_url":"https://github.com/cdepillabout.png","language":"Haskell","funding_links":["https://github.com/sponsors/cdepillabout"],"categories":["Haskell"],"sub_categories":[],"readme":"\nText.Pretty.Simple\n==================\n\n[![Build Status](https://github.com/cdepillabout/pretty-simple/workflows/CI/badge.svg)](https://github.com/cdepillabout/pretty-simple/actions)\n[![Hackage](https://img.shields.io/hackage/v/pretty-simple.svg)](https://hackage.haskell.org/package/pretty-simple)\n[![Stackage LTS](http://stackage.org/package/pretty-simple/badge/lts)](http://stackage.org/lts/package/pretty-simple)\n[![Stackage Nightly](http://stackage.org/package/pretty-simple/badge/nightly)](http://stackage.org/nightly/package/pretty-simple)\n![BSD3 license](https://img.shields.io/badge/license-BSD3-blue.svg)\n\n`pretty-simple` is a pretty printer for Haskell data types that have a `Show`\ninstance.\n\nFor example, imagine the following Haskell data types and values:\n\n```haskell\ndata Foo = Foo { foo1 :: Integer , foo2 :: [String] } deriving Show\n\nfoo :: Foo\nfoo = Foo 3 [\"hello\", \"goodbye\"]\n\ndata Bar = Bar { bar1 :: Double , bar2 :: [Foo] } deriving Show\n\nbar :: Bar\nbar = Bar 10.55 [foo, foo]\n```\n\nIf you run this in `ghci` and type `print bar`, you'll get output like this:\n\n```haskell\n\u003e print bar\nBar {bar1 = 10.55, bar2 = [Foo {foo1 = 3, foo2 = [\"hello\",\"goodbye\"]},Foo {foo1 = 3, foo2 = [\"hello\",\"goodbye\"]}]}\n```\n\nThis is pretty hard to read.  Imagine if there were more fields or it were even\nmore deeply nested.  It would be even more difficult to read.\n\n`pretty-simple` can be used to print `bar` in an easy-to-read format:\n\n![example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-example-screenshot.png)\n\n## Usage\n\n`pretty-simple` can be easily used from `ghci` when debugging.\n\nWhen using `stack` to run `ghci`, just append the `--package` flag to\nthe command line to load `pretty-simple`:\n\n```sh\n$ stack ghci --package pretty-simple\n```\n\nOr, with cabal:\n\n```sh\n$ cabal repl --build-depends pretty-simple\n```\n\nOnce you get a prompt in `ghci`, you can use `import` to get `pretty-simple`'s\n[`pPrint`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pPrint)\nfunction in scope.\n\n```haskell\n\u003e import Text.Pretty.Simple (pPrint)\n```\n\nYou can test out `pPrint` with simple data types like `Maybe` or tuples.\n\n```haskell\n\u003e pPrint $ Just (\"hello\", \"goodbye\")\nJust\n    ( \"hello\"\n    , \"goodbye\"\n    )\n```\n\nIf 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):\n```hs\npPrint :: Show a =\u003e a -\u003e IO ()\npPrint = putStrLn \u003c=\u003c readProcess \"pretty-simple\" [] . show\n```\n\nThere'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.\n\n## Features\n\n- Easy-to-read\n    - Complex data types are simple to understand.\n- Color\n    - Prints in color using ANSI escape codes.\n    - It is possible to print without color by using the\n      [`pPrintNoColor`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pPrintNoColor)\n      function.\n- Rainbow Parentheses\n    - Easy to understand deeply nested data types.\n- Configurable\n    - Indentation, compactness, colors and more are configurable with the\n      [`pPrintOpt`](https://hackage.haskell.org/package/pretty-simple-1.0.0.6/docs/Text-Pretty-Simple.html#v:pPrintOpt)\n      function.\n- Fast\n    - No problem pretty-printing data types thousands of lines long.\n- Works with any data type with a `Show` instance\n    - Some common Haskell data types have a `Show` instance that produces\n      non-valid Haskell code.  `pretty-simple` will pretty-print even these\n      data types.\n\n## Why not `(some other package)`?\n\nOther pretty-printing packages have some combination of these defects:\n\n- No options for printing in color.\n- No options for changing the amount of indentation\n- Requires every data type to be an instance of some special typeclass (instead\n  of just `Show`).\n- Requires all `Show` instances to output valid Haskell code.\n\n## Other Uses\n\n### Pretty-print all GHCi output\n\nThe `pPrint` function can be used as the default output function in GHCi.\n\nAll you need to do is run GHCi with a command like one of these:\n\n```sh\n$ stack ghci --ghci-options \"-interactive-print=Text.Pretty.Simple.pPrint\" --package pretty-simple\n```\n```sh\n$ cabal repl --repl-options \"-interactive-print=Text.Pretty.Simple.pPrint\" --build-depends pretty-simple\n```\n\nNow, whenever you make GHCi evaluate an expression, GHCi will pretty-print the\nresult using `pPrint`!  See\n[here](https://downloads.haskell.org/%7Eghc/latest/docs/html/users_guide/ghci.html#using-a-custom-interactive-printing-function)\nfor more info on this neat feature in GHCi.\n\n### Pretty-printing JSON\n\n`pretty-simple` can be used to pretty-print any `String` that is similar to\nHaskell data types.  The only requirement is that the `String` must correctly\nuse brackets, parenthese, and braces to indicate nesting.\n\nFor example, the\n[`pString`](https://hackage.haskell.org/package/pretty-simple/docs/Text-Pretty-Simple.html#v:pString)\nfunction can be used to pretty-print JSON.\n\nRecall our example from before.\n\n```haskell\ndata Foo = Foo { foo1 :: Integer , foo2 :: [String] } deriving Show\n\nfoo :: Foo\nfoo = Foo 3 [\"hello\", \"goodbye\"]\n\ndata Bar = Bar { bar1 :: Double , bar2 :: [Foo] } deriving Show\n\nbar :: Bar\nbar = Bar 10.55 [foo, foo]\n```\n\nYou can use [`aeson`](https://hackage.haskell.org/package/aeson) to turn these\ndata types into JSON.  First, you must derive\n[`ToJSON`](https://hackage.haskell.org/package/aeson/docs/Data-Aeson.html#t:ToJSON)\ninstances for the data types.  It is easiest to do this with Template Haskell:\n\n```haskell\n{-# LANGUAGE TemplateHaskell #-}\n\n$(deriveJSON defaultOptions ''Foo)\n$(deriveJSON defaultOptions ''Bar)\n```\n\nIf you run this in `ghci` and type `encode bar`, you'll get output like this:\n\n```haskell\n\u003e import Data.Aeson (encode)\n\u003e putLazyByteStringLn $ encode bar\n{\"bar1\":10.55,\"bar2\":[{\"foo1\":3,\"foo2\":[\"hello\",\"goodbye\"]},{\"foo1\":3,\"foo2\":[\"hello\",\"goodbye\"]}]}\n```\n\nJust like Haskell's normal `print` output, this is pretty hard to read.\n\n`pretty-simple` can be used to pretty-print the JSON-encoded `bar` in an\neasy-to-read format:\n\n![json example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-json-example-screenshot.png)\n\n(You can find the `lazyByteStringToString`, `putLazyByteStringLn`,\nand `putLazyTextLn` in the [`ExampleJSON.hs`](example/ExampleJSON.hs)\nfile.)\n\n### Pretty-printing from the command line\n\n`pretty-simple` includes a command line executable that can be used to\npretty-print anything passed in on stdin.\n\nIt can be installed to `~/.local/bin/` with the following command.\n\n```sh\n$ stack install pretty-simple\n```\n\nWhen run on the command line, you can paste in the Haskell datatype you want to\nbe formatted, then hit \u003ckbd\u003eCtrl\u003c/kbd\u003e-\u003ckbd\u003eD\u003c/kbd\u003e:\n\n![cli example screenshot](https://raw.githubusercontent.com/cdepillabout/pretty-simple/master/img/pretty-simple-cli-screenshot.png)\n\nThis is very useful if you accidentally print out a Haskell data type with\n`print` instead of `pPrint`.\n\n## Contributions\n\nFeel free to open an\n[issue](https://github.com/cdepillabout/pretty-simple/issues) or\n[PR](https://github.com/cdepillabout/pretty-simple/pulls) for any\nbugs/problems/suggestions/improvements.\n\n### Testing\n\nTo run the test suite locally, one must install the executables `doctest` and\n`cabal-doctest`, e.g. with\n`cabal install --ignore-project doctest --flag cabal-doctest`.\n\nThen run the command `cabal doctest`.\n\n## Maintainers\n\n- [@cdepillabout](https://github.com/cdepillabout)\n- [@georgefst](https://github.com/georgefst)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdepillabout%2Fpretty-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdepillabout%2Fpretty-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdepillabout%2Fpretty-simple/lists"}