Commit 1b5e83d1 authored by Robert Henderson's avatar Robert Henderson
Browse files

Added 'flatStyle' to Distribution.Text.

'flatStyle' is a rendering style for the pretty-printer that
renders all on one line.
parent 8a246551
......@@ -15,6 +15,7 @@ module Distribution.Text (
Text(..),
defaultStyle,
display,
flatStyle,
simpleParse,
stdParse,
) where
......@@ -31,16 +32,29 @@ class Text a where
disp :: a -> Disp.Doc
parse :: Parse.ReadP r a
-- | The default rendering style used in Cabal for console output.
-- | The default rendering style used in Cabal for console
-- output. It has a fixed page width and adds line breaks
-- automatically.
defaultStyle :: Disp.Style
defaultStyle = Disp.Style { Disp.mode = Disp.PageMode
, Disp.lineLength = 79
, Disp.ribbonsPerLine = 1.0
}
-- | Pretty-prints with the default style.
display :: Text a => a -> String
display = Disp.renderStyle defaultStyle . disp
-- | A style for rendering all on one line.
flatStyle :: Disp.Style
flatStyle = Disp.Style { Disp.mode = Disp.LeftMode
, Disp.lineLength = err "lineLength"
, Disp.ribbonsPerLine = err "ribbonsPerLine"
}
where
err x = error ("flatStyle: tried to access " ++ x ++ " in LeftMode. " ++
"This should never happen and indicates a bug in Cabal.")
simpleParse :: Text a => String -> Maybe a
simpleParse str = case [ p | (p, s) <- Parse.readP_to_S parse str
, all isSpace s ] of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment