module Futhark.Util.Pretty
( module Text.PrettyPrint.Mainland
, module Text.PrettyPrint.Mainland.Class
, pretty
, prettyDoc
, prettyTuple
, prettyText
, prettyOneLine
, apply
, oneLine
, annot
, nestedBlock
)
where
import Data.Text (Text)
import qualified Data.Text.Lazy as LT
import Text.PrettyPrint.Mainland hiding (pretty)
import Text.PrettyPrint.Mainland.Class
import qualified Text.PrettyPrint.Mainland as PP
pretty :: Pretty a => a -> String
pretty = PP.pretty 80 . ppr
prettyText :: Pretty a => a -> Text
prettyText = LT.toStrict . PP.prettyLazyText 80 . ppr
prettyOneLine :: Pretty a => a -> String
prettyOneLine = ($"") . displayS . renderCompact . oneLine . ppr
prettyDoc :: Int -> Doc -> String
prettyDoc = PP.pretty
ppTuple' :: Pretty a => [a] -> Doc
ppTuple' ets = braces $ commasep $ map ppr ets
prettyTuple :: Pretty a => [a] -> String
prettyTuple = PP.pretty 80 . ppTuple'
apply :: [Doc] -> Doc
apply = parens . commasep . map align
oneLine :: PP.Doc -> PP.Doc
oneLine s = PP.text $ PP.displayS (PP.renderCompact s) ""
annot :: [Doc] -> Doc -> Doc
annot [] s = s
annot l s = stack l </> s
nestedBlock :: String -> String -> Doc -> Doc
nestedBlock pre post body = text pre </>
PP.indent 2 body </>
text post