cdepillabout / pretty-simple

pretty-printer for Haskell data types that have a Show instance
https://hackage.haskell.org/package/pretty-simple
BSD 3-Clause "New" or "Revised" License
243 stars 29 forks source link

document how to use pretty-simple as default ghci printer #108

Open nasosev opened 2 years ago

nasosev commented 2 years ago

I have pretty-simple set as the default printer for my project by putting the following in my .ghci file at the root of the project:

:set -ignore-package pretty-simple -package pretty-simple
:def! pretty \ _ -> pure ":set -interactive-print Text.Pretty.Simple.pPrint"
:pretty

How can I also enable the compact output option for the default printer?

Thanks a lot.

georgefst commented 2 years ago

Yeah, I'd like to flesh out that section of documentation a little. I started looking in to it properly once, but the whole process of writing .ghci files is fraught with awkward edge cases. Especially when needing to import packages. For one thing, I've never been clear about the rules around qualifying imports. I eventually got hung up on https://github.com/haskell/cabal/issues/7789. There are definitely upstream improvements to be made, in GHC as well as Cabal.

Anyway, this works for me on GHC 9.2:

import Text.Pretty.Simple
ghciInteractivePrint = pPrintOpt CheckColorTty defaultOutputOptionsDarkBg{outputOptionsCompact = True}
:set -interactive-print ghciInteractivePrint
nasosev commented 2 years ago

Thank you. That works for me if I input it within the ghci repl, but it does not work automatically when I put it in my .ghci file (my project is using LTS 19.2 for ghc-9.0.2).

scarf005 commented 1 year ago

I tried the above comment's solution and set up ~/.ghci to this:

import Text.Pretty.Simple

ghciInteractivePrint = pPrintOpt CheckColorTty defaultOutputOptionsDarkBg{outputOptionsCompact = True}
:set -interactive-print ghciInteractivePrint

image

however it doesn't seem to work and I have to manually type them to work. could anyone help me figure out what's the problem?

georgefst commented 1 year ago

Yeah, I've ended up often using cabal repl -b pretty-simple --repl-options="-interactive-print Text.Pretty.Simple.pPrintForceColor" because the .ghci solution doesn't always work (see https://github.com/haskell/cabal/issues/7789).