11{-# LANGUAGE CPP #-}
2+ {-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
23module Options.Applicative.Help.Pretty
34 ( module Text.PrettyPrint.ANSI.Leijen
5+ , Doc
6+ , indent
7+ , renderPretty
8+ , displayS
49 , (.$.)
510 , groupOrNestLine
611 , altSep
712 , hangAtIfOver
813 ) where
914
10- import Control.Applicative
1115#if !MIN_VERSION_base(4,11,0)
1216import Data.Semigroup ((<>) )
1317#endif
1418
15- import Text.PrettyPrint.ANSI.Leijen hiding ((<$>) , (<>) , columns )
16- import Text.PrettyPrint.ANSI.Leijen.Internal (Doc (.. ), flatten )
19+ import Text.PrettyPrint.ANSI.Leijen hiding (Doc , (<$>) , (<>) , columns , indent , renderPretty , displayS )
1720import qualified Text.PrettyPrint.ANSI.Leijen as PP
1821
1922import Prelude
2023
24+ type Doc = PP. Doc
25+
26+ indent :: Int -> PP. Doc -> PP. Doc
27+ indent = PP. indent
28+
29+ renderPretty :: Float -> Int -> PP. Doc -> SimpleDoc
30+ renderPretty = PP. renderPretty
31+
32+ displayS :: SimpleDoc -> ShowS
33+ displayS = PP. displayS
34+
2135(.$.) :: Doc -> Doc -> Doc
2236(.$.) = (PP. <$>)
2337
@@ -38,8 +52,8 @@ ifAtRoot =
3852-- start of our nesting level.
3953ifElseAtRoot :: (Doc -> Doc ) -> (Doc -> Doc ) -> Doc -> Doc
4054ifElseAtRoot f g doc =
41- Nesting $ \ i ->
42- Column $ \ j ->
55+ nesting $ \ i ->
56+ column $ \ j ->
4357 if i == j
4458 then f doc
4559 else g doc
@@ -52,9 +66,7 @@ ifElseAtRoot f g doc =
5266-- group.
5367groupOrNestLine :: Doc -> Doc
5468groupOrNestLine =
55- Union
56- <$> flatten
57- <*> ifNotAtRoot (line <> ) . nest 2
69+ group . ifNotAtRoot (linebreak <> ) . nest 2
5870
5971
6072-- | Separate items in an alternative with a pipe.
@@ -85,7 +97,7 @@ altSep x y =
8597-- the starting column, and it won't be indented more.
8698hangAtIfOver :: Int -> Int -> Doc -> Doc
8799hangAtIfOver i j d =
88- Column $ \ k ->
100+ column $ \ k ->
89101 if k <= j then
90102 align d
91103 else
0 commit comments