-- | A constructor we can wrap around values to avoid any built in
-- Pretty instance - for example, instance Pretty [a].
--
--  * display is now prettyShow
--  * display' is now prettyText
--  * ppDisplay is now ppShow
--  * ppDisplay' is now ppText
{-# LANGUAGE DeriveFunctor, FlexibleContexts, FlexibleInstances, OverloadedStrings, TypeSynonymInstances #-}
module Debian.Pretty
    ( PP(PP, unPP)
    , prettyText
    , ppPrint
    , ppShow
    , ppText
    -- * Re-export
    , prettyShow
    ) where

import Data.Text (Text, unpack, pack)
import Text.PrettyPrint.HughesPJClass (Doc, text, empty)
import Distribution.Pretty (Pretty(pretty), prettyShow)

-- | This type is wrapped around values before we pretty print them so
-- we can write our own Pretty instances for common types without
-- polluting the name space of clients of this package with instances
-- they don't want.
newtype PP a = PP {forall a. PP a -> a
unPP :: a} deriving (forall a b. a -> PP b -> PP a
forall a b. (a -> b) -> PP a -> PP b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PP b -> PP a
$c<$ :: forall a b. a -> PP b -> PP a
fmap :: forall a b. (a -> b) -> PP a -> PP b
$cfmap :: forall a b. (a -> b) -> PP a -> PP b
Functor)

instance Pretty (PP Text) where
    pretty :: PP Text -> Doc
pretty = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PP a -> a
unPP

instance Pretty (PP String) where
    pretty :: PP String -> Doc
pretty = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PP a -> a
unPP

instance Pretty (PP a) => Pretty (PP (Maybe a)) where
    pretty :: PP (Maybe a) -> Doc
pretty = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty forall a. Pretty (PP a) => a -> Doc
ppPrint forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PP a -> a
unPP

prettyText :: Pretty a => a -> Text
prettyText :: forall a. Pretty a => a -> Text
prettyText = String -> Text
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Pretty a => a -> String
prettyShow

ppPrint :: Pretty (PP a) => a -> Doc
ppPrint :: forall a. Pretty (PP a) => a -> Doc
ppPrint = forall a. Pretty a => a -> Doc
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> PP a
PP

ppShow :: Pretty (PP a) => a -> String
ppShow :: forall a. Pretty (PP a) => a -> String
ppShow = forall a. Pretty a => a -> String
prettyShow forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> PP a
PP

ppText :: Pretty (PP a) => a -> Text
ppText :: forall a. Pretty (PP a) => a -> Text
ppText = String -> Text
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Pretty a => a -> String
prettyShow forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> PP a
PP