From 426090b605e841bbcc3ab0c3f2df943cb1696bd8 Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Tue, 31 May 2022 13:24:36 +0800 Subject: [PATCH] further reduce newlines for compact output (#84) added a doctest reflecting the more compact [(a,b)] output --- src/Text/Pretty/Simple.hs | 9 +++++++++ src/Text/Pretty/Simple/Internal/Printer.hs | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Text/Pretty/Simple.hs b/src/Text/Pretty/Simple.hs index c6a21b0..13a7cf9 100644 --- a/src/Text/Pretty/Simple.hs +++ b/src/Text/Pretty/Simple.hs @@ -680,6 +680,15 @@ layoutStringAnsi opts = fmap convertStyle . layoutString opts -- , B -- ( B ( B A ) ) ] ) -- +-- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ [("id", 123), ("state", 1), ("pass", 1), ("tested", 100), ("time", 12345)] +-- [ +-- ( "id", 123 ), +-- ( "state", 1 ), +-- ( "pass", 1 ), +-- ( "tested", 100 ), +-- ( "time", 12345 ) +-- ] +-- -- __Initial indent__ -- -- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsInitialIndent = 3} $ B ( B ( B ( B A ) ) ) diff --git a/src/Text/Pretty/Simple/Internal/Printer.hs b/src/Text/Pretty/Simple/Internal/Printer.hs index 14c64ae..8c3c5c4 100644 --- a/src/Text/Pretty/Simple/Internal/Printer.hs +++ b/src/Text/Pretty/Simple/Internal/Printer.hs @@ -255,7 +255,10 @@ prettyExpr opts = (if outputOptionsCompact opts then group else id) . \case spaceIfNeeded = \case Other (' ' : _) : _ -> mempty _ -> space - lineAndCommaSep x y = x <> line' <> annotate Comma "," <> y + lineAndCommaSep x y = + if outputOptionsCompact opts + then x <> annotate Comma "," <> y + else x <> line' <> annotate Comma "," <> y -- | Determine whether this expression should be displayed on a single line. isSimple :: Expr -> Bool