1module Options.Applicative.Help.Types ( 2 ParserHelp (..) 3 , renderHelp 4 ) where 5 6import Data.Semigroup 7import Prelude 8 9import Options.Applicative.Help.Chunk 10import Options.Applicative.Help.Pretty 11 12data ParserHelp = ParserHelp 13 { helpError :: Chunk Doc 14 , helpSuggestions :: Chunk Doc 15 , helpHeader :: Chunk Doc 16 , helpUsage :: Chunk Doc 17 , helpBody :: Chunk Doc 18 , helpGlobals :: Chunk Doc 19 , helpFooter :: Chunk Doc } 20 21instance Show ParserHelp where 22 showsPrec _ h = showString (renderHelp 80 h) 23 24instance Monoid ParserHelp where 25 mempty = ParserHelp mempty mempty mempty mempty mempty mempty mempty 26 mappend = (<>) 27 28instance Semigroup ParserHelp where 29 (ParserHelp e1 s1 h1 u1 b1 g1 f1) <> (ParserHelp e2 s2 h2 u2 b2 g2 f2) 30 = ParserHelp (mappend e1 e2) (mappend s1 s2) 31 (mappend h1 h2) (mappend u1 u2) 32 (mappend b1 b2) (mappend g1 g2) 33 (mappend f1 f2) 34 35helpText :: ParserHelp -> Doc 36helpText (ParserHelp e s h u b g f) = extractChunk . vsepChunks $ [e, s, h, u, b, g, f] 37 38-- | Convert a help text to 'String'. 39renderHelp :: Int -> ParserHelp -> String 40renderHelp cols 41 = (`displayS` "") 42 . renderPretty 1.0 cols 43 . helpText 44