Skip to content

Commit

Permalink
further reduce newlines for compact output (cdepillabout#84)
Browse files Browse the repository at this point in the history
added a doctest for a simple Value type
  • Loading branch information
juhp committed Jun 4, 2022
1 parent 380829e commit eaba4b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Text/Pretty/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ layoutStringAnsi opts = fmap convertStyle . layoutString opts
-- , B
-- ( B ( B A ) ) ] )
--
-- >>> data Value = ValueStruct [(String,Value)] | ValueInt Int deriving Show
--
-- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ ValueStruct [("id", ValueInt 123), ("state", ValueInt 1)]
-- ValueStruct
-- [ ( "id", ValueInt 123 ), ( "state", ValueInt 1 ) ]
--
-- __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 eaba4b2

Please sign in to comment.