module Agda.Utils.Pretty
( module Agda.Utils.Pretty
, module Text.PrettyPrint
) where
import Data.Function
import Data.Int ( Int32 )
import Data.Monoid
import Text.PrettyPrint hiding (TextDetails(Str), empty)
import Agda.Utils.Null
instance Null Doc where
empty = mempty
null = (== mempty)
class Pretty a where
pretty :: a -> Doc
prettyPrec :: Int -> a -> Doc
pretty = prettyPrec 0
prettyPrec = const pretty
prettyShow :: Pretty a => a -> String
prettyShow = render . pretty
instance Pretty Bool where pretty = text . show
instance Pretty Int where pretty = text . show
instance Pretty Int32 where pretty = text . show
instance Pretty Integer where pretty = text . show
instance Pretty Char where
pretty c = text [c]
instance Pretty Doc where
pretty = id
instance Pretty String where
pretty = text
#if !MIN_VERSION_pretty(1,1,2)
instance Eq Doc where
(==) = (==) `on` render
#endif
pwords :: String -> [Doc]
pwords = map text . words
fwords :: String -> Doc
fwords = fsep . pwords
mparens :: Bool -> Doc -> Doc
mparens True = parens
mparens False = id
align :: Int -> [(String, Doc)] -> Doc
align max rows =
vcat $ map (\(s, d) -> text s $$ nest (maxLen + 1) d) $ rows
where maxLen = maximum $ 0 : filter (< max) (map (length . fst) rows)