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 , helpFooter :: Chunk Doc } 19 20instance Show ParserHelp where 21 showsPrec _ h = showString (renderHelp 80 h) 22 23instance Monoid ParserHelp where 24 mempty = ParserHelp mempty mempty mempty mempty mempty mempty 25 mappend = (<>) 26 27instance Semigroup ParserHelp where 28 (ParserHelp e1 s1 h1 u1 b1 f1) <> (ParserHelp e2 s2 h2 u2 b2 f2) 29 = ParserHelp (mappend e1 e2) (mappend s1 s2) 30 (mappend h1 h2) (mappend u1 u2) 31 (mappend b1 b2) (mappend f1 f2) 32 33helpText :: ParserHelp -> Doc 34helpText (ParserHelp e s h u b f) = extractChunk . vsepChunks $ [e, s, h, u, b, f] 35 36-- | Convert a help text to 'String'. 37renderHelp :: Int -> ParserHelp -> String 38renderHelp cols 39 = (`displayS` "") 40 . renderPretty 1.0 cols 41 . helpText 42