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

[rfe] option for compact (complex) lists: avoid rendering lines with only a comma #93

Closed juhp closed 3 years ago

juhp commented 3 years ago

I really like the simplicity of this library, though I do wish it defaulted to more compact output. 8-)

Simple lists render nicely:

> pPrint ["one","two"]
[ "one"
, "two"
]

But for complicated lists using available compact options:

> import Network.XmlRpc.Internals
> pPrintOpt CheckColorTty (defaultOutputOptionsDarkBg {outputOptionsCompact = True, 
                                                       outputOptionsCompactParens = True})
    [("resultCode",ValueInt 10),("resultText",ValueString "build completed in 5m 12s")]

[
    ( "resultCode", ValueInt 10 )
,
    ( "resultText", ValueString "build completed in 5m 12s" ) ]

This is a small example, but for rendering large Map's etc, having the comma on a separate line takes up a lot of vertical space. Maybe outputOptionsCompactParens should induce putting the comma on the same line?

I would love to just have a pPrintCompact function to provide such compact output (the above usage is already rather long).

further edit: perhaps the initial newline could be dropped too, to something like this?:

[   ( "resultCode", ValueInt 10 )
,   ( "resultText", ValueString "build completed in 5m 12s" ) ]
georgefst commented 3 years ago

I think this is covered by #84, except for pPrintCompact, which is possibly a good idea. Could you open that part as a separate issue? Then I'll close this and you can subscribe to #84.

juhp commented 3 years ago

Okay, thanks