{-# OPTIONS_HADDOCK hide #-}
module Distribution.PrettyUtils (
Separator,
showFilePath,
showToken,
showTestedWith,
showFreeText,
indentWith,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Compiler (CompilerFlavor)
import Distribution.Version (VersionRange)
import Distribution.Text (disp)
import Text.PrettyPrint (Doc, text, vcat, (<+>))
type Separator = ([Doc] -> Doc)
showFilePath :: FilePath -> Doc
showFilePath "" = mempty
showFilePath x = showToken x
showToken :: String -> Doc
showToken str
| not (any dodgy str) && not (null str) = text str
| otherwise = text (show str)
where
dodgy c = isSpace c || c == ','
showTestedWith :: (CompilerFlavor, VersionRange) -> Doc
showTestedWith (compiler, vr) = text (show compiler) <+> disp vr
showFreeText :: String -> Doc
showFreeText "" = mempty
showFreeText s = vcat [text (if null l then "." else l) | l <- lines_ s]
lines_ :: String -> [String]
lines_ [] = [""]
lines_ s = let (l, s') = break (== '\n') s
in l : case s' of
[] -> []
(_:s'') -> lines_ s''
indentWith :: Int
indentWith = 4