Skip to content
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

Add option for initial indentation #71

Merged
merged 2 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Text/Pretty/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,13 @@ layoutStringAnsi opts = fmap convertStyle . layoutString opts
-- , B
-- ( B ( B A ) ) ] )
--
-- __Initial indent__
-- >>> pPrintOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsInitialIndent = 3} $ B ( B ( B ( B A ) ) )
-- B
-- ( B
-- ( B ( B A ) )
-- )
--
-- __Other__
--
-- Making sure the spacing after a string is correct.
Expand Down
8 changes: 6 additions & 2 deletions src/Text/Pretty/Simple/Internal/OutputPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Data.List (dropWhileEnd)
import Data.List.NonEmpty (NonEmpty, nonEmpty)
import Data.Maybe (fromMaybe)
import Prettyprinter
(line', PageWidth(AvailablePerLine), layoutPageWidth, nest, hsep,
(indent, line', PageWidth(AvailablePerLine), layoutPageWidth, nest, hsep,
concatWith, space, Doc, SimpleDocStream, annotate, defaultLayoutOptions,
enclose, hcat, layoutSmart, line, unAnnotateS, pretty)
import Data.Typeable (Typeable)
Expand Down Expand Up @@ -102,6 +102,8 @@ data OutputOptions = OutputOptions
-- ^ Use less vertical (and more horizontal) space.
, outputOptionsCompactParens :: Bool
-- ^ Group closing parentheses on to a single line.
, outputOptionsInitialIndent :: Int
-- ^ Indent the whole output by this amount.
, outputOptionsColorOptions :: Maybe ColorOptions
-- ^ If this is 'Nothing', then don't colorize the output. If this is
-- @'Just' colorOptions@, then use @colorOptions@ to colorize the output.
Expand Down Expand Up @@ -173,6 +175,7 @@ defaultOutputOptionsNoColor =
, outputOptionsPageWidth = 80
, outputOptionsCompact = False
, outputOptionsCompactParens = False
, outputOptionsInitialIndent = 0
, outputOptionsColorOptions = Nothing
, outputOptionsStringStyle = EscapeNonPrintable
}
Expand Down Expand Up @@ -206,7 +209,8 @@ layoutString opts =
prettyExprs' :: OutputOptions -> [Expr] -> Doc Annotation
prettyExprs' opts = \case
[] -> mempty
x : xs -> prettyExpr opts x <> prettyExprs opts xs
x : xs -> indent (outputOptionsInitialIndent opts)
$ prettyExpr opts x <> prettyExprs opts xs

-- | Construct a 'Doc' from multiple 'Expr's.
prettyExprs :: OutputOptions -> [Expr] -> Doc Annotation
Expand Down