From 426090b605e841bbcc3ab0c3f2df943cb1696bd8 Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Tue, 31 May 2022 13:24:36 +0800 Subject: [PATCH 1/4] 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 From fc0c6bae61c1cef0e8f74f3ed437c1e2333a8601 Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Sat, 4 Jun 2022 22:45:51 +0800 Subject: [PATCH 2/4] stack: update to final lts-18 --- stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index 40321c8..f372e8a 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,7 +1,7 @@ # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-18.02 +resolver: lts-18.28 # Local packages, usually specified by relative directory name packages: From 132eac244e23fc39228dd229f0d1e2e12dcdbad7 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sat, 4 Jun 2022 18:28:39 +0200 Subject: [PATCH 3/4] refactor: DRY `lineAndCommaSep` --- src/Text/Pretty/Simple/Internal/Printer.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Text/Pretty/Simple/Internal/Printer.hs b/src/Text/Pretty/Simple/Internal/Printer.hs index 8c3c5c4..b150640 100644 --- a/src/Text/Pretty/Simple/Internal/Printer.hs +++ b/src/Text/Pretty/Simple/Internal/Printer.hs @@ -255,10 +255,7 @@ prettyExpr opts = (if outputOptionsCompact opts then group else id) . \case spaceIfNeeded = \case Other (' ' : _) : _ -> mempty _ -> space - lineAndCommaSep x y = - if outputOptionsCompact opts - then x <> annotate Comma "," <> y - else x <> line' <> annotate Comma "," <> y + lineAndCommaSep x y = x <> (if outputOptionsCompact opts then mempty else line') <> annotate Comma "," <> y -- | Determine whether this expression should be displayed on a single line. isSimple :: Expr -> Bool From 844be683381c5f7b5b1c4c8523db185be8401771 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Sat, 4 Jun 2022 18:44:37 +0200 Subject: [PATCH 4/4] refactor: Use `munless` in `lineAndCommaSep` --- src/Text/Pretty/Simple/Internal/Printer.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Text/Pretty/Simple/Internal/Printer.hs b/src/Text/Pretty/Simple/Internal/Printer.hs index b150640..8185989 100644 --- a/src/Text/Pretty/Simple/Internal/Printer.hs +++ b/src/Text/Pretty/Simple/Internal/Printer.hs @@ -255,7 +255,8 @@ prettyExpr opts = (if outputOptionsCompact opts then group else id) . \case spaceIfNeeded = \case Other (' ' : _) : _ -> mempty _ -> space - lineAndCommaSep x y = x <> (if outputOptionsCompact opts then mempty else line') <> annotate Comma "," <> y + lineAndCommaSep x y = x <> munless (outputOptionsCompact opts) line' <> annotate Comma "," <> y + munless b x = if b then mempty else x -- | Determine whether this expression should be displayed on a single line. isSimple :: Expr -> Bool