From 2d25ad252eb5099685cc9969578779233f6e3d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 18 Sep 2024 11:47:37 +0200 Subject: [PATCH] Allow to tune the brief description renderer --- src/Options/Applicative.hs | 1 + src/Options/Applicative/Builder.hs | 7 ++++++- src/Options/Applicative/Help/Core.hs | 2 +- src/Options/Applicative/Types.hs | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Options/Applicative.hs b/src/Options/Applicative.hs index a76de74..b714c13 100644 --- a/src/Options/Applicative.hs +++ b/src/Options/Applicative.hs @@ -202,6 +202,7 @@ module Options.Applicative ( helpLongEquals, helpShowGlobals, helpIndent, + briefHangPoint, defaultPrefs, -- * Completions diff --git a/src/Options/Applicative/Builder.hs b/src/Options/Applicative/Builder.hs index 6f57b66..b59c1cd 100644 --- a/src/Options/Applicative/Builder.hs +++ b/src/Options/Applicative/Builder.hs @@ -90,6 +90,7 @@ module Options.Applicative.Builder ( helpLongEquals, helpShowGlobals, helpIndent, + briefHangPoint, prefs, defaultPrefs, @@ -582,6 +583,9 @@ helpShowGlobals = PrefsMod $ \p -> p { prefHelpShowGlobal = True } helpIndent :: Int -> PrefsMod helpIndent w = PrefsMod $ \p -> p { prefTabulateFill = w } +-- | Set the width at which to hang the brief help text. +briefHangPoint :: Int -> PrefsMod +briefHangPoint php = PrefsMod $ \p -> p { prefBriefHangPoint = php } -- | Create a `ParserPrefs` given a modifier @@ -597,7 +601,8 @@ prefs m = applyPrefsMod m base , prefColumns = 80 , prefHelpLongEquals = False , prefHelpShowGlobal = False - , prefTabulateFill = 24 } + , prefTabulateFill = 24 + , prefBriefHangPoint = 35 } -- Convenience shortcuts diff --git a/src/Options/Applicative/Help/Core.hs b/src/Options/Applicative/Help/Core.hs index b63dcbb..f193f0e 100644 --- a/src/Options/Applicative/Help/Core.hs +++ b/src/Options/Applicative/Help/Core.hs @@ -414,7 +414,7 @@ parserUsage pprefs p progn = hsep [ pretty "Usage:", pretty progn, - hangAtIfOver 9 35 (extractChunk (briefDesc pprefs p)) + hangAtIfOver 9 (prefBriefHangPoint pprefs) (extractChunk (briefDesc pprefs p)) ] -- | Peek at the structure of the rendered tree within. diff --git a/src/Options/Applicative/Types.hs b/src/Options/Applicative/Types.hs index caaa6a0..6639de4 100644 --- a/src/Options/Applicative/Types.hs +++ b/src/Options/Applicative/Types.hs @@ -127,7 +127,8 @@ data ParserPrefs = ParserPrefs , prefHelpShowGlobal :: Bool -- ^ when displaying subparsers' usage help, -- show parent options under a "global options" -- section (default: False) - , prefTabulateFill ::Int -- ^ Indentation width for tables + , prefTabulateFill ::Int -- ^ Indentation width for tables + , prefBriefHangPoint :: Int -- ^ Width at which to hang the brief description } deriving (Eq, Show) data OptName = OptShort !Char