mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-09-11 10:45:25 +03:00
Nest union types which flow over multiple lines
This commit is contained in:
parent
5478fc16cb
commit
27c3a9ecfe
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user