module Options.Applicative.Help.Pretty
( module Text.PrettyPrint.ANSI.Leijen
, (.$.)
, groupOrNestLine
, altSep
) where
import Control.Applicative
import Data.Semigroup ((<>))
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>), columns)
import Text.PrettyPrint.ANSI.Leijen.Internal (Doc (..), flatten)
import qualified Text.PrettyPrint.ANSI.Leijen as PP
import Prelude
(.$.) :: Doc -> Doc -> Doc
.$. :: Doc -> Doc -> Doc
(.$.) = Doc -> Doc -> Doc
(PP.<$>)
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
ifNotAtRoot Doc -> Doc
f Doc
doc =
(Int -> Doc) -> Doc
Nesting ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
i ->
(Int -> Doc) -> Doc
Column ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
j ->
if Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
j
then Doc
doc
else Doc -> Doc
f Doc
doc
groupOrNestLine :: Doc -> Doc
groupOrNestLine :: Doc -> Doc
groupOrNestLine =
Doc -> Doc -> Doc
Union
(Doc -> Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc -> Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Doc -> Doc
flatten
(Doc -> Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Doc -> Doc) -> Doc -> Doc
ifNotAtRoot (Doc
line Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<>) (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> Doc
nest Int
2
altSep :: Doc -> Doc -> Doc
altSep :: Doc -> Doc -> Doc
altSep Doc
x Doc
y =
Doc -> Doc
group (Doc
x Doc -> Doc -> Doc
<+> Char -> Doc
char Char
'|' Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
line) Doc -> Doc -> Doc
<//> Doc
y