module Debian.Pretty
( PP(PP, unPP)
, prettyShow
, prettyText
, ppPrint
, ppShow
, ppText
) where
import Data.Text (Text, unpack, pack)
import Text.PrettyPrint.HughesPJClass (Doc, Pretty(pPrint), text, empty, prettyShow)
newtype PP a = PP {unPP :: a} deriving (Functor)
instance Pretty (PP Text) where
pPrint = text . unpack . unPP
instance Pretty (PP String) where
pPrint = text . unPP
instance Pretty (PP a) => Pretty (PP (Maybe a)) where
pPrint = maybe empty ppPrint . unPP
prettyText :: Pretty a => a -> Text
prettyText = pack . prettyShow
ppPrint :: Pretty (PP a) => a -> Doc
ppPrint = pPrint . PP
ppShow :: Pretty (PP a) => a -> String
ppShow = prettyShow . PP
ppText :: Pretty (PP a) => a -> Text
ppText = pack . prettyShow . PP