Skip to content

Instantly share code, notes, and snippets.

@chshersh
Last active December 5, 2023 00:19
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chshersh/9111d97578413323ba1b191299c54235 to your computer and use it in GitHub Desktop.
Save chshersh/9111d97578413323ba1b191299c54235 to your computer and use it in GitHub Desktop.
Config for GHCi with pretty output
-- To run:
-- cabal repl -b pretty-simple
--
-- Colorizing and pretty-printing ghci output
-- requires: pretty-simple
:set -interactive-print=Text.Pretty.Simple.pPrint
-- green bold lambdas and multiline mode
:set prompt "\ESC[1;32mλ: \ESC[m"
:set prompt-cont "\ESC[1;32mλ| \ESC[m"
-- useful flags
:set -fprint-explicit-foralls
:set +m
-- useful extensions by default
:set -XTypeApplications -XKindSignatures
-- useful default imports
import Data.Kind (Type, Constraint)
-- helpful macros
:def package \ m -> return $ ":! ghc-pkg --simple-output find-module " ++ m
:def no-pretty \_ -> return (":set -interactive-print=System.IO.print")
:def rr \_ -> return ":script ~/.ghc/ghci.conf"
@AurevoirXavier
Copy link

AurevoirXavier commented Jul 22, 2020

How can I use this in a project?

I have to specify the package.

stack ghci --package pretty-show --package hscolour --package heredoc

And I run stack ghci, it will be override. Loaded GHCi configuration from /tmp/haskell-stack-ghci/f00796c9/ghci-script

@chshersh
Copy link
Author

Hi @AurevoirXavier, I no longer use this particular GHCi config. My new global GHCi config is much smaller. Also, I'm now using cabal almost all the time for development instead of stack. Cabal doesn't have such an issue, I can run cabal repl -b pretty-simple from any place and any project and it will work automatically. I've updated this gist to reflect my latest config and not confuse people in the future 🙂

@AurevoirXavier
Copy link

I found the problem. The :load will drop pre define things something like ghciColor.
pretty-simple sounds like a good solution.

@AurevoirXavier
Copy link

AurevoirXavier commented Jul 23, 2020

Here's my modification. It also works for stack, whatever you're under a stack project or not.

Thanks @chshersh

:def pretty \_ -> return (":set -interactive-print=Text.Pretty.Simple.pPrint")
:def no-pretty \_ -> return (":set -interactive-print System.IO.print")

:def package \m -> return $ ":! ghc-pkg --simple-output find-module " ++ m
:def rr \_ -> return ":script ~/.ghci"

:set prompt  "\ESC[1;32mλ \ESC[m"

:set +m
:set +s
:set +t

:set -package pretty-simple

:set -fprint-explicit-foralls
:set -interactive-print=Text.Pretty.Simple.pPrint
:set -XTypeApplications -XKindSignatures

import Data.Kind (Type, Constraint)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment