module TextShow.Text.PrettyPrint (
renderB
, renderStyleB
, showbMode
, showbStylePrec
, showbTextDetailsPrec
#if MIN_VERSION_pretty(1,1,2)
, showbPrettyLevelPrec
#endif
) where
import Data.Monoid.Compat
import Text.PrettyPrint.HughesPJ (Doc, Mode, Style(..), TextDetails(..),
fullRender, style)
#if MIN_VERSION_pretty(1,1,2)
import Text.PrettyPrint.HughesPJClass (PrettyLevel)
#endif
import TextShow (TextShow(showb, showbPrec), Builder, fromString, singleton)
import TextShow.TH (deriveTextShow)
#include "inline.h"
renderB :: Doc -> Builder
renderB = renderStyleB style
renderStyleB :: Style -> Doc -> Builder
renderStyleB sty doc = fullRender (mode sty)
(lineLength sty)
(ribbonsPerLine sty)
txtPrinter
mempty
doc
txtPrinter :: TextDetails -> Builder -> Builder
txtPrinter (Chr c) b = singleton c <> b
txtPrinter (Str s') b = fromString s' <> b
txtPrinter (PStr s') b = fromString s' <> b
showbMode :: Mode -> Builder
showbMode = showb
showbStylePrec :: Int -> Style -> Builder
showbStylePrec = showbPrec
showbTextDetailsPrec :: Int -> TextDetails -> Builder
showbTextDetailsPrec = showbPrec
#if MIN_VERSION_pretty(1,1,2)
showbPrettyLevelPrec :: Int -> PrettyLevel -> Builder
showbPrettyLevelPrec = showbPrec
#endif
instance TextShow Doc where
showb = renderB
INLINE_INST_FUN(showb)
$(deriveTextShow ''Mode)
$(deriveTextShow ''Style)
$(deriveTextShow ''TextDetails)
#if MIN_VERSION_pretty(1,1,2)
$(deriveTextShow ''PrettyLevel)
#endif