pretty-ghci: Functionality for beautifying GHCi

[ bsd3, library, program, text ] [ Propose Tags ]

Provides a library and an executable for parsing and pretty-printing the output of derived Show instances as well as Haddock docstrings. The idea is to provide functionality that can be easily plugged into GHCi's -interactive-print option, making for a better REPL experience.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.6), base (>=4.9 && <4.13), haddock-library (>=1.7 && <1.8), pretty-ghci, prettyprinter (>=1.2 && <1.3), prettyprinter-ansi-terminal (>=1.1 && <1.2), text (>=1.2 && <1.3), Win32 (>=2.6.2) [details]
License BSD-3-Clause
Copyright (c) Alec Theriault
Author Alec Theriault
Maintainer alec.theriault@gmail.com
Category Text
Source repo head: git clone https://github.com/harpocrates/pretty-ghci.git
Uploaded by harpocrates at 2019-04-16T14:55:23Z
Distributions
Executables pp-ghci
Downloads 953 total (6 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-04-16 [all 1 reports]

Readme for pretty-ghci-0.2.0.0

[back to package description]

pretty-ghci Travis Status Appveyor Status Hackage

This library will make your GHCi experience colourful in 3 steps:

  1. Install the executable globally with cabal v2-install pretty-ghci

  2. Modify your ~/.ghc/ghci.conf

    :set prompt      "λ> "
    :set prompt-cont "|> "
    
    -- Typing `:pretty` will turn on the pretty-printing
    :set -package process
    :{
    :def pretty \_ -> pure $ unlines $
      [ ":{"
      , "let pprint x = System.Process.withCreateProcess cp' $ \\(Just i) _ _ ph -> do"
      , "        System.IO.hPutStrLn i (show x)"
      , "        System.IO.hClose i"
      , "        _ <- System.Process.waitForProcess ph"
      , "        pure ()"
      , "      where cp = System.Process.proc \"pp-ghci\" [\"--value\", \"--smarter-layout\"]"
      , "            cp' = cp{ System.Process.std_out = System.Process.Inherit"
      , "                    , System.Process.std_err = System.Process.Inherit"
      , "                    , System.Process.std_in  = System.Process.CreatePipe }"
      , ":}"
      , ":set -interactive-print pprint"
      ]
    :}
    
    -- Typing `:no-pretty` will turn off the pretty-printing
    :def no-pretty \_ -> pure (":set -interactive-print System.IO.print")
    
    -- Make things pretty by default!
    :pretty
    
  3. Enjoy!

Advantages over existing alternatives

  • One stop-solution for formatting and coloring with a small dependency graph
  • Takes your terminal width into account during the layout step
  • Works for values whose Show instance don't produce valid Haskell (ex: Show (->))
  • Handles unboxed literals (ex: MyTriple 1# 2.0# "hello"#)
  • Your output will be coloured according to its lexical structure even if parsing fails
  • Install one global executable, not one library per GHC version
  • Works in cabal repl (although you need to call :pretty once at the start)