Nest union types which flow over multiple lines

This commit is contained in:
Huw Campbell 2019-07-18 18:14:39 +10:00
parent 5478fc16cb
commit 27c3a9ecfe
2 changed files with 11 additions and 6 deletions

View File

@ -130,7 +130,7 @@ foldTree (MultNode xs)
= (foldr ((<</>>) . wrap NoDefault . foldTree) mempty xs, Bare)
foldTree (AltNode b xs)
= (\x -> (x, Bare))
. fmap groupOrLine
. fmap groupOrNestLine
. wrap b
. alt_node
. filter (not . isEmpty . fst)

View File

@ -1,7 +1,7 @@
module Options.Applicative.Help.Pretty
( module Text.PrettyPrint.ANSI.Leijen
, (.$.)
, groupOrLine
, groupOrNestLine
) where
import Control.Applicative
@ -16,7 +16,8 @@ import Prelude
(.$.) :: Doc -> Doc -> Doc
(.$.) = (PP.<$>)
-- | Apply the funcion if we're not at the
-- | Apply the function if we're not at the
-- start of our nesting level.
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
ifNotAtRoot f doc =
@ -26,10 +27,14 @@ ifNotAtRoot f doc =
then doc
else f doc
-- | Render flattened text on this line, or start
-- a new line before rendering any text.
groupOrLine :: Doc -> Doc
groupOrLine =
--
-- This will also nest subsequent lines in the
-- group.
groupOrNestLine :: Doc -> Doc
groupOrNestLine =
Union
<$> flatten
<*> ifNotAtRoot (mappend line)
<*> ifNotAtRoot (mappend line) . nest 2