-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Compact" option sometimes produces ugly/inconsistent output #84
Comments
Yep, agreed that's unfortunate. Adding I'll try to look in to this, but it's unlikely to be particularly high-priority for me in the near future. If you're willing to investigate yourself, the key function is prettyExpr. It's admittedly a bit dense, but you'll see that compactness currently just means applying |
Well, what do you know, I've actually just hit this myself, and it is a little annoying. So that's a slight bump in priority. |
For posterity, mine is: x :: IO ()
x = pPrintOpt CheckColorTty opts
(
( 1, 2 )
, Result
{ a = True, b = False }
)
where
opts =
defaultOutputOptionsDarkBg
{ outputOptionsCompact = True
, outputOptionsPageWidth = 40
} Ideally, I'd like the constructor ( |
Thanks for pretty-simple ! hledger has switched to it. Possibly related to this issue: if it could produce slightly more compact output the way pretty-show did, that would be even better. Eg:
|
@simonmichael Yeah, I agree that would be preferable. As I mentioned further up the thread, the compact mode is really a one line hack, so there hasn't been any thought put in to these edge cases. I'll have a think about how easy this particular one would be to fix. |
I assume you're doing something other than calling |
@georgefst no I'm just doing: prettyopts =
defaultOutputOptionsDarkBg
-- defaultOutputOptionsLightBg
-- defaultOutputOptionsNoColor
{ outputOptionsIndentAmount=2
, outputOptionsCompact=True
}
-- | Pretty print. Generic alias for pretty-simple's pPrint.
pprint :: Show a => a -> IO ()
pprint = pPrintOpt CheckColorTty prettyopts |
Okay, with that and: data CsvRules = CsvRules
{ rdirectives :: [(String, String)]
, rcsvfieldindexes :: [(String, Int)]
, rassignments :: [(String, String)]
, rconditionalblocks :: [()]
}
deriving (Show)
main = pprint CsvRules
{ rdirectives = [("skip", "1")]
, rcsvfieldindexes = [("date", 1), ("amount", 2)]
, rassignments = [("amount", "%2"), ("date", "%1")]
, rconditionalblocks = []
} I'm getting: CsvRules
{ rdirectives =
[ ( "skip", "1" ) ]
, rcsvfieldindexes =
[ ( "date", 1 ), ( "amount", 2 ) ]
, rassignments =
[ ( "amount", "%2" ), ( "date", "%1" ) ]
, rconditionalblocks = []
} Do you not? Does |
Aha, yes it does: https://github.com/simonmichael/hledger/blob/master/hledger-lib/Hledger/Read/CsvReader.hs#L267 . That's our bug, thanks for looking into it. |
PS, just more brainstorming: aligning equals signs (capped at some not-too-large width) might be nice for readability:
|
added a doctest for a simple Value type
added a doctest reflecting the more compact [(a,b)] output
I'm going to keep this open despite #110, seeing as the output for #84 (comment) is still odd: (
( 1, 2 ), Result
{ a = True, b = False }
) There's also #84 (comment), though that's unrelated to the main thrust of this issue, which is about making compact mode more compact. Perhaps, @simonmichael, you might open a separate issue if you're still interested? |
I spent a little time looking at this yesterday actually, |
Yes, that sounds reasonable! |
One thing to possibly watch out for is to make sure not to remove the ability to pretty-print an infinite data structure. Currently the parsing and pretty-printing in > pPrint (repeat [(Just [1,2,3], ("hello", "bye"))])
[
[
( Just
[ 1
, 2
, 3
]
,
( "hello"
, "bye"
)
)
]
,
[
( Just
[ 1
, 2
, 3
]
...
^C
> Depending on how you're thinking of implementing this, you'll may want to watch out that you don't accidentally remove this lazy parsing / pretty-printing ability. This was added in #9. |
Oh, and I realized that currently > pPrintOpt CheckColorTty defaultOutputOptionsDarkBg { outputOptionsCompact = True } (repeat 3) This doesn't print anything. Maybe I should make a separate issue about this... |
I'm using a custom pPrintOpt config which looks like this:
I'm getting some weird behaviour when printing long lists of tuples with this compact option. If I print a list of 10 integer values, the printing works as expected:
If I define a simple ADT, it also works fine:
However, if I try and print a list of tuples, the output seems to insert extra newlines after the commas:
I would not expect these newlines to be here. Instead, the expected output would be similar to the previous examples, where the comma is on the same line as the value.
The text was updated successfully, but these errors were encountered: