mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-09-11 10:45:25 +03:00
Merge pull request #354 from pcapriotti/topic/improve-readability
Improve readability of help text
This commit is contained in:
commit
5478fc16cb
@ -112,7 +112,7 @@ briefDesc' showOptional pprefs
|
|||||||
, descHidden = False }
|
, descHidden = False }
|
||||||
|
|
||||||
-- | Wrap a doc in parentheses or brackets if required.
|
-- | Wrap a doc in parentheses or brackets if required.
|
||||||
wrap :: AltNodeType -> (Chunk Doc, Wrapping) -> Chunk Doc
|
wrap :: AltNodeType -> (Chunk Doc, Wrapping) -> Chunk Doc
|
||||||
wrap altnode (chunk, wrapping)
|
wrap altnode (chunk, wrapping)
|
||||||
| altnode == MarkDefault
|
| altnode == MarkDefault
|
||||||
= fmap brackets chunk
|
= fmap brackets chunk
|
||||||
@ -130,11 +130,13 @@ foldTree (MultNode xs)
|
|||||||
= (foldr ((<</>>) . wrap NoDefault . foldTree) mempty xs, Bare)
|
= (foldr ((<</>>) . wrap NoDefault . foldTree) mempty xs, Bare)
|
||||||
foldTree (AltNode b xs)
|
foldTree (AltNode b xs)
|
||||||
= (\x -> (x, Bare))
|
= (\x -> (x, Bare))
|
||||||
|
. fmap groupOrLine
|
||||||
. wrap b
|
. wrap b
|
||||||
. alt_node
|
. alt_node
|
||||||
. filter (not . isEmpty . fst)
|
. filter (not . isEmpty . fst)
|
||||||
. map foldTree $ xs
|
. map foldTree $ xs
|
||||||
where
|
where
|
||||||
|
|
||||||
alt_node :: [(Chunk Doc, Wrapping)] -> (Chunk Doc, Wrapping)
|
alt_node :: [(Chunk Doc, Wrapping)] -> (Chunk Doc, Wrapping)
|
||||||
alt_node [n] = n
|
alt_node [n] = n
|
||||||
alt_node ns = (\y -> (y, Wrapped))
|
alt_node ns = (\y -> (y, Wrapped))
|
||||||
|
@ -1,10 +1,35 @@
|
|||||||
module Options.Applicative.Help.Pretty
|
module Options.Applicative.Help.Pretty
|
||||||
( module Text.PrettyPrint.ANSI.Leijen
|
( module Text.PrettyPrint.ANSI.Leijen
|
||||||
, (.$.)
|
, (.$.)
|
||||||
|
, groupOrLine
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>), columns)
|
import Control.Applicative
|
||||||
|
import Data.Monoid (mappend)
|
||||||
|
|
||||||
|
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>), columns)
|
||||||
|
import Text.PrettyPrint.ANSI.Leijen.Internal (Doc (..), flatten)
|
||||||
import qualified Text.PrettyPrint.ANSI.Leijen as PP
|
import qualified Text.PrettyPrint.ANSI.Leijen as PP
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
(.$.) :: Doc -> Doc -> Doc
|
(.$.) :: Doc -> Doc -> Doc
|
||||||
(.$.) = (PP.<$>)
|
(.$.) = (PP.<$>)
|
||||||
|
|
||||||
|
-- | Apply the funcion if we're not at the
|
||||||
|
-- start of our nesting level.
|
||||||
|
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
|
||||||
|
ifNotAtRoot f doc =
|
||||||
|
Nesting $ \i ->
|
||||||
|
Column $ \j ->
|
||||||
|
if i == j
|
||||||
|
then doc
|
||||||
|
else f doc
|
||||||
|
|
||||||
|
-- | Render flattened text on this line, or start
|
||||||
|
-- a new line before rendering any text.
|
||||||
|
groupOrLine :: Doc -> Doc
|
||||||
|
groupOrLine =
|
||||||
|
Union
|
||||||
|
<$> flatten
|
||||||
|
<*> ifNotAtRoot (mappend line)
|
||||||
|
Loading…
Reference in New Issue
Block a user