Skip to content

Commit 2b3b129

Browse files
authored
Merge pull request #473 from pcapriotti/topic/bump-pretty-printer
Bump pretty printer and stop relying on its internal modules.
2 parents 08fc3c8 + 79f3a63 commit 2b3b129

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
- Widen bounds for `ansi-wl-pprint`. This supports the use of `prettyprinter`
4+
in a non-breaking way, as the `ansi-wl-pprint > 1.0` support the newer
5+
library.
6+
37
- Export `helpIndent` from `Options.Applicative`.
48

59
- Export completion script generators from `Options.Applicative.BashCompletion`.

optparse-applicative.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ library
103103
build-depends: base == 4.*
104104
, transformers >= 0.2 && < 0.7
105105
, transformers-compat >= 0.3 && < 0.8
106-
, ansi-wl-pprint >= 0.6.8 && < 0.7
106+
, ansi-wl-pprint >= 0.6.8 && < 1.1
107107

108108
if flag(process)
109109
build-depends: process >= 1.0 && < 1.7

src/Options/Applicative/BashCompletion.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
12
-- | You don't need to import this module to enable bash completion.
23
--
34
-- See
45
-- <http://github.com/pcapriotti/optparse-applicative/wiki/Bash-Completion the wiki>
56
-- for more information on bash completion.
67
module Options.Applicative.BashCompletion
7-
( bashCompletionParser,
8+
( bashCompletionParser,
9+
810
bashCompletionScript,
911
fishCompletionScript,
1012
zshCompletionScript,

src/Options/Applicative/Help/Chunk.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
12
module Options.Applicative.Help.Chunk
23
( Chunk(..)
34
, chunked

src/Options/Applicative/Help/Core.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
23
module Options.Applicative.Help.Core (
34
cmdDesc,
45
briefDesc,
@@ -24,7 +25,7 @@ import Control.Monad (guard)
2425
import Data.Function (on)
2526
import Data.List (sort, intersperse, groupBy)
2627
import Data.Foldable (any, foldl')
27-
import Data.Maybe (maybeToList, catMaybes, fromMaybe)
28+
import Data.Maybe (catMaybes, fromMaybe)
2829
#if !MIN_VERSION_base(4,8,0)
2930
import Data.Monoid (mempty)
3031
#endif

src/Options/Applicative/Help/Pretty.hs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
{-# LANGUAGE CPP #-}
2+
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
23
module Options.Applicative.Help.Pretty
34
( module Text.PrettyPrint.ANSI.Leijen
5+
, Doc
6+
, indent
7+
, renderPretty
8+
, displayS
49
, (.$.)
510
, groupOrNestLine
611
, altSep
712
, hangAtIfOver
813
) where
914

10-
import Control.Applicative
1115
#if !MIN_VERSION_base(4,11,0)
1216
import Data.Semigroup ((<>))
1317
#endif
1418

15-
import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>), columns)
16-
import Text.PrettyPrint.ANSI.Leijen.Internal (Doc (..), flatten)
19+
import Text.PrettyPrint.ANSI.Leijen hiding (Doc, (<$>), (<>), columns, indent, renderPretty, displayS)
1720
import qualified Text.PrettyPrint.ANSI.Leijen as PP
1821

1922
import Prelude
2023

24+
type Doc = PP.Doc
25+
26+
indent :: Int -> PP.Doc -> PP.Doc
27+
indent = PP.indent
28+
29+
renderPretty :: Float -> Int -> PP.Doc -> SimpleDoc
30+
renderPretty = PP.renderPretty
31+
32+
displayS :: SimpleDoc -> ShowS
33+
displayS = PP.displayS
34+
2135
(.$.) :: Doc -> Doc -> Doc
2236
(.$.) = (PP.<$>)
2337

@@ -38,8 +52,8 @@ ifAtRoot =
3852
-- start of our nesting level.
3953
ifElseAtRoot :: (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
4054
ifElseAtRoot f g doc =
41-
Nesting $ \i ->
42-
Column $ \j ->
55+
nesting $ \i ->
56+
column $ \j ->
4357
if i == j
4458
then f doc
4559
else g doc
@@ -52,9 +66,7 @@ ifElseAtRoot f g doc =
5266
-- group.
5367
groupOrNestLine :: Doc -> Doc
5468
groupOrNestLine =
55-
Union
56-
<$> flatten
57-
<*> ifNotAtRoot (line <>) . nest 2
69+
group . ifNotAtRoot (linebreak <>) . nest 2
5870

5971

6072
-- | Separate items in an alternative with a pipe.
@@ -85,7 +97,7 @@ altSep x y =
8597
-- the starting column, and it won't be indented more.
8698
hangAtIfOver :: Int -> Int -> Doc -> Doc
8799
hangAtIfOver i j d =
88-
Column $ \k ->
100+
column $ \k ->
89101
if k <= j then
90102
align d
91103
else

tests/test.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,12 +949,11 @@ prop_long_command_line_flow = once $
949949
---
950950

951951
deriving instance Arbitrary a => Arbitrary (Chunk a)
952-
deriving instance Eq SimpleDoc
953-
deriving instance Show SimpleDoc
952+
954953

955954
equalDocs :: Float -> Int -> Doc -> Doc -> Property
956-
equalDocs f w d1 d2 = Doc.renderPretty f w d1
957-
=== Doc.renderPretty f w d2
955+
equalDocs f w d1 d2 = Doc.displayS (Doc.renderPretty f w d1) ""
956+
=== Doc.displayS (Doc.renderPretty f w d2) ""
958957

959958
prop_listToChunk_1 :: [String] -> Property
960959
prop_listToChunk_1 xs = isEmpty (listToChunk xs) === null xs

0 commit comments

Comments
 (0)