1 module Distribution
.Pretty
18 import Distribution
.CabalSpecVersion
19 import Distribution
.Compat
.Prelude
22 import qualified Text
.PrettyPrint
as PP
27 prettyVersioned
:: CabalSpecVersion
-> a
-> PP
.Doc
28 prettyVersioned _
= pretty
31 instance Pretty PP
.Doc
where
34 instance Pretty
Bool where
35 pretty
= PP
.text
. show
37 instance Pretty
Int where
38 pretty
= PP
.text
. show
40 instance Pretty a
=> Pretty
(Identity a
) where
41 pretty
= pretty
. runIdentity
43 prettyShow
:: Pretty a
=> a
-> String
44 prettyShow
= PP
.renderStyle defaultStyle
. pretty
46 -- | The default rendering style used in Cabal for console
47 -- output. It has a fixed page width and adds line breaks
49 defaultStyle
:: PP
.Style
52 { PP
.mode
= PP
.PageMode
54 , PP
.ribbonsPerLine
= 1.0
57 -- | A style for rendering all on one line.
61 { PP
.mode
= PP
.LeftMode
62 , PP
.lineLength
= err
"lineLength"
63 , PP
.ribbonsPerLine
= err
"ribbonsPerLine"
68 ( "flatStyle: tried to access "
71 ++ "This should never happen and indicates a bug in Cabal."
74 -------------------------------------------------------------------------------
76 -------------------------------------------------------------------------------
78 -- TODO: remove when ReadP parser is gone.
79 type Separator
= [PP
.Doc
] -> PP
.Doc
81 showFilePath
:: FilePath -> PP
.Doc
82 showFilePath
= showToken
84 showToken
:: String -> PP
.Doc
85 showToken
= PP
.text
. showTokenStr
87 showTokenStr
:: String -> String
89 -- if token looks like a comment (starts with --), print it in quotes
90 |
"--" `
isPrefixOf` str
= show str
91 -- also if token ends with a colon (e.g. executable name), print it in quotes
92 |
":" `
isSuffixOf` str
= show str
93 |
not (any dodgy str
) && not (null str
) = str
94 |
otherwise = show str
96 dodgy c
= isSpace c || c
== ','
98 -- | Pretty-print free-format text, ensuring that it is vertically aligned,
99 -- and with blank lines replaced by dots for correct re-parsing.
100 showFreeText
:: String -> PP
.Doc
101 showFreeText
"" = mempty
102 showFreeText s
= PP
.vcat
[PP
.text
(if null l
then "." else l
) | l
<- lines_ s
]
104 -- | Pretty-print free-format text.
105 -- Since @cabal-version: 3.0@ we don't replace blank lines with dots.
108 showFreeTextV3
:: String -> PP
.Doc
109 showFreeTextV3
"" = mempty
110 showFreeTextV3 s
= PP
.vcat
[PP
.text l | l
<- lines_ s
]
112 -- | 'lines_' breaks a string up into a list of strings at newline
113 -- characters. The resulting strings do not contain newlines.
114 lines_
:: String -> [String]
117 let (l
, s
') = break (== '\n') s
120 (_
: s
'') -> lines_ s
''