From 89f4c66d75a89395b6e955c5c472821326cd8024 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 9 Jun 2020 23:48:03 +0100 Subject: [PATCH 1/2] Add option for initial indentation --- src/Text/Pretty/Simple/Internal/OutputPrinter.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Text/Pretty/Simple/Internal/OutputPrinter.hs b/src/Text/Pretty/Simple/Internal/OutputPrinter.hs index 9c6abfb..86c065c 100644 --- a/src/Text/Pretty/Simple/Internal/OutputPrinter.hs +++ b/src/Text/Pretty/Simple/Internal/OutputPrinter.hs @@ -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) @@ -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. @@ -173,6 +175,7 @@ defaultOutputOptionsNoColor = , outputOptionsPageWidth = 80 , outputOptionsCompact = False , outputOptionsCompactParens = False + , outputOptionsInitialIndent = 0 , outputOptionsColorOptions = Nothing , outputOptionsStringStyle = EscapeNonPrintable } @@ -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 From 2b8a43076a2d2ebc726091e5d6922f6a71d905d1 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Wed, 19 Aug 2020 01:44:50 +0100 Subject: [PATCH 2/2] Add test for initial indentation --- src/Text/Pretty/Simple.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Text/Pretty/Simple.hs b/src/Text/Pretty/Simple.hs index 9be8a50..6f97fef 100644 --- a/src/Text/Pretty/Simple.hs +++ b/src/Text/Pretty/Simple.hs @@ -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.