Skip to content

Commit

Permalink
further reduce newlines for compact output (#84)
Browse files Browse the repository at this point in the history
added a doctest reflecting the more compact [(a,b)] output
  • Loading branch information
juhp committed Jun 4, 2022
1 parent 380829e commit 426090b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Text/Pretty/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) )
Expand Down
5 changes: 4 additions & 1 deletion src/Text/Pretty/Simple/Internal/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 426090b

Please sign in to comment.