MyNixOS website logo
Description

Functionality for beautifying GHCi.

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.

pretty-ghciTravis 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)
Metadata

Version

0.2.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows