Skip to content

Commit 270a626

Browse files
authored
Merge pull request pcapriotti#476 from pcapriotti/topic/0.18.1
Use layoutPretty instead of layoutSmart when rendering help texts.
2 parents eccd532 + 0713e59 commit 270a626

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## Version 0.18.1.0 (29 May 2023)
2+
3+
- Change pretty printer layout algorithm used.
4+
5+
The layoutSmart algorithm appears to be extremely slow with some command line
6+
sets, to the point where the program appears to hang.
7+
8+
Fixes issues:
9+
* \# 476 - Stack executable 'hangs' with 0.17.1 and 0.18.0.
10+
11+
- Render help text with `AnsiStyle` aware rendering functions.
12+
113
## Version 0.18.0.0 (22 May 2023)
214

315
- Move to 'prettyprinter` library for pretty printing.

optparse-applicative.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: optparse-applicative
2-
version: 0.18.0.0
2+
version: 0.18.1.0
33
synopsis: Utilities and combinators for parsing command line options
44
description:
55
optparse-applicative is a haskell library for parsing options
@@ -101,6 +101,7 @@ library
101101
, Options.Applicative.Internal
102102

103103
build-depends: base >= 4.5 && < 5
104+
, text >= 1.2
104105
, transformers >= 0.2 && < 0.7
105106
, transformers-compat >= 0.3 && < 0.8
106107
, prettyprinter >= 1.7 && < 1.8

src/Options/Applicative/Builder.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ showDefault = showDefaultWith show
189189
help :: String -> Mod f a
190190
help s = optionMod $ \p -> p { propHelp = paragraph s }
191191

192-
-- | Specify the help text for an option as a 'Text.PrettyPrint.ANSI.Leijen.Doc'
192+
-- | Specify the help text for an option as a 'Prettyprinter.Doc AnsiStyle'
193193
-- value.
194194
helpDoc :: Maybe Doc -> Mod f a
195195
helpDoc doc = optionMod $ \p -> p { propHelp = Chunk doc }
@@ -215,7 +215,7 @@ hidden = optionMod $ \p ->
215215
-- | Apply a function to the option description in the usage text.
216216
--
217217
-- > import Options.Applicative.Help
218-
-- > flag' () (short 't' <> style bold)
218+
-- > flag' () (short 't' <> style (annotate bold))
219219
--
220220
-- /NOTE/: This builder is more flexible than its name and example
221221
-- allude. One of the motivating examples for its addition was to
@@ -402,7 +402,7 @@ briefDesc = InfoMod $ \i -> i { infoFullDesc = False }
402402
header :: String -> InfoMod a
403403
header s = InfoMod $ \i -> i { infoHeader = paragraph s }
404404

405-
-- | Specify a header for this parser as a 'Text.PrettyPrint.ANSI.Leijen.Doc'
405+
-- | Specify a header for this parser as a 'Prettyprinter.Doc AnsiStyle'
406406
-- value.
407407
headerDoc :: Maybe Doc -> InfoMod a
408408
headerDoc doc = InfoMod $ \i -> i { infoHeader = Chunk doc }
@@ -411,7 +411,7 @@ headerDoc doc = InfoMod $ \i -> i { infoHeader = Chunk doc }
411411
footer :: String -> InfoMod a
412412
footer s = InfoMod $ \i -> i { infoFooter = paragraph s }
413413

414-
-- | Specify a footer for this parser as a 'Text.PrettyPrint.ANSI.Leijen.Doc'
414+
-- | Specify a footer for this parser as a 'Prettyprinter.Doc AnsiStyle'
415415
-- value.
416416
footerDoc :: Maybe Doc -> InfoMod a
417417
footerDoc doc = InfoMod $ \i -> i { infoFooter = Chunk doc }
@@ -420,7 +420,7 @@ footerDoc doc = InfoMod $ \i -> i { infoFooter = Chunk doc }
420420
progDesc :: String -> InfoMod a
421421
progDesc s = InfoMod $ \i -> i { infoProgDesc = paragraph s }
422422

423-
-- | Specify a short program description as a 'Text.PrettyPrint.ANSI.Leijen.Doc'
423+
-- | Specify a short program description as a 'Prettyprinter.Doc AnsiStyle'
424424
-- value.
425425
progDescDoc :: Maybe Doc -> InfoMod a
426426
progDescDoc doc = InfoMod $ \i -> i { infoProgDesc = Chunk doc }

src/Options/Applicative/Help/Pretty.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ module Options.Applicative.Help.Pretty
1818
#if !MIN_VERSION_base(4,11,0)
1919
import Data.Semigroup ((<>), mempty)
2020
#endif
21+
import qualified Data.Text.Lazy as Lazy
2122

2223
import Prettyprinter hiding (Doc)
2324
import qualified Prettyprinter as PP
24-
import qualified Prettyprinter.Render.String as PP
2525
import Prettyprinter.Render.Terminal
2626

2727
import Prelude
2828

29-
type Doc = PP.Doc Prettyprinter.Render.Terminal.AnsiStyle
29+
type Doc = PP.Doc AnsiStyle
3030
type SimpleDoc = SimpleDocStream AnsiStyle
3131

3232
linebreak :: Doc
@@ -106,7 +106,7 @@ hangAtIfOver i j d =
106106

107107
renderPretty :: Double -> Int -> Doc -> SimpleDocStream AnsiStyle
108108
renderPretty ribbonFraction lineWidth
109-
= layoutSmart LayoutOptions
109+
= layoutPretty LayoutOptions
110110
{ layoutPageWidth = AvailablePerLine lineWidth ribbonFraction }
111111

112112
prettyString :: Double -> Int -> Doc -> String
@@ -115,5 +115,9 @@ prettyString ribbonFraction lineWidth
115115
. renderPretty ribbonFraction lineWidth
116116

117117
streamToString :: SimpleDocStream AnsiStyle -> String
118-
streamToString stream =
119-
PP.renderShowS stream ""
118+
streamToString sdoc =
119+
let
120+
rendered =
121+
Prettyprinter.Render.Terminal.renderLazy sdoc
122+
in
123+
Lazy.unpack rendered

0 commit comments

Comments
 (0)