wl-pprint-console 0.0.1.2 → 0.1.0.0
raw patch · 2 files changed
+61/−48 lines, 2 filesdep +bytestringdep +colorful-monoidsdep −console-styledep −mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring, colorful-monoids
Dependencies removed: console-style, mtl
API changes (from Hackage documentation)
- Text.PrettyPrint.Console.WL: displayStyle :: MonadIO m => (a -> [SetStyle]) -> SimpleDoc a -> m ()
- Text.PrettyPrint.Console.WL: displayStyleCode :: Monoid o => (String -> o) -> (a -> [SetStyle]) -> Term -> SimpleDoc a -> o
- Text.PrettyPrint.Console.WL: displayStyleCodeS :: (a -> [SetStyle]) -> Term -> SimpleDoc a -> ShowS
- Text.PrettyPrint.Console.WL: displayStyleCodeT :: (a -> [SetStyle]) -> Term -> SimpleDoc a -> Text
- Text.PrettyPrint.Console.WL: hDisplayStyle :: MonadIO m => Handle -> (a -> [SetStyle]) -> SimpleDoc a -> m ()
- Text.PrettyPrint.Console.WL: hPutDocStyle :: Handle -> (a -> [SetStyle]) -> Doc a -> IO ()
- Text.PrettyPrint.Console.WL: putDocStyle :: (a -> [SetStyle]) -> Doc a -> IO ()
+ Text.PrettyPrint.Console.WL: displayB :: SimpleDoc a -> ByteString
+ Text.PrettyPrint.Console.WL: displayColored :: (String -> o) -> (a -> [Colored o]) -> SimpleDoc a -> [Colored o]
+ Text.PrettyPrint.Console.WL: displayColoredB :: (a -> [Colored Builder]) -> Term -> SimpleDoc a -> ByteString
+ Text.PrettyPrint.Console.WL: displayColoredS :: (a -> [Colored String]) -> Term -> SimpleDoc a -> ShowS
+ Text.PrettyPrint.Console.WL: displayColoredT :: (a -> [Colored Builder]) -> Term -> SimpleDoc a -> Text
+ Text.PrettyPrint.Console.WL: displayHTMLB :: (a -> String) -> SimpleDoc a -> ByteString
+ Text.PrettyPrint.Console.WL: displayWrappedB :: SimpleDoc (String, String) -> ByteString
+ Text.PrettyPrint.Console.WL: hPutDocColored :: Handle -> Term -> (a -> [Colored String]) -> Doc a -> IO ()
+ Text.PrettyPrint.Console.WL: putDocColored :: Term -> (a -> [Colored String]) -> Doc a -> IO ()
Files
src/Text/PrettyPrint/Console/WL.hs view
@@ -18,25 +18,36 @@ module Text.PrettyPrint.Annotated.WL -- * Display documents annotated with pairs of strings- , displayWrapped, displayWrappedT, displayWrappedS+ , displayWrapped, displayWrappedT, displayWrappedB, displayWrappedS -- * Display as HTML- , displayHTML, displayHTMLT, displayHTMLS+ , displayHTML, displayHTMLT, displayHTMLB, displayHTMLS -- * Display with ANSI escape sequences- , displayStyleCode, displayStyleCodeT, displayStyleCodeS+ , displayColoredT, displayColoredB, displayColoredS -- * Display to a file handle with ANSI escape sequences- , hDisplayStyle, displayStyle, hPutDocStyle, putDocStyle+ , displayColored, hPutDocColored, putDocColored++ -- * Display without annotations (Missing from wl-pprint-annotated)+ , displayB ) where import Text.PrettyPrint.Annotated.WL-import System.Console.Style-import Control.Monad.Trans+import Data.Monoid.Colorful.Flat import System.IO (Handle, hPutStr, stdout) import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Builder as TL+import qualified Data.ByteString.Lazy as BL+import qualified Data.ByteString.Builder as BL +-- | @(display simpleDoc)@ takes the output @simpleDoc@ from a+-- rendering function and outputs a 'ByteString'. Along the way, all annotations are+-- discarded.+displayB :: SimpleDoc a -> BL.ByteString+displayB = BL.toLazyByteString . displayDecorated cm cm BL.stringUtf8+ where cm = const mempty+ -- | Escape a HTML string by replacing special characters with HTML entities. escapeHTML :: String -> String escapeHTML = concatMap $ \c ->@@ -64,6 +75,14 @@ displayWrappedT = TL.toLazyText . displayWrapped TL.fromString -- | Display a rendered document which is annotated with pairs of strings @(String,String)@ and+-- output 'ByteString'.+--+-- The first element of the pair is prepended to the annotated region,+-- the second after the annotated region.+displayWrappedB :: SimpleDoc (String, String) -> BL.ByteString+displayWrappedB = BL.toLazyByteString . displayWrapped BL.stringUtf8++-- | Display a rendered document which is annotated with pairs of strings @(String,String)@ and -- output a 'ShowS' function. -- -- The first element of the pair is prepended to the annotated region,@@ -88,6 +107,13 @@ displayHTMLT :: (a -> String) -> SimpleDoc a -> TL.Text displayHTMLT f = TL.toLazyText . displayHTML TL.fromString f +-- | Display a rendered document as HTML and output 'ByteString'.+--+-- The annotated region is wrapped by @<span class="f a">..</span>@ with the @class@ attribute+-- given by the annotation function.+displayHTMLB :: (a -> String) -> SimpleDoc a -> BL.ByteString+displayHTMLB f = BL.toLazyByteString . displayHTML BL.stringUtf8 f+ -- | Display a rendered document as HTML and output a 'ShowS' function. -- -- The annotated region is wrapped by @<span class="f a">..</span>@ with the @class@ attribute@@ -95,56 +121,43 @@ displayHTMLS :: (a -> String) -> SimpleDoc a -> ShowS displayHTMLS f = (++) . displayHTML id f --- | Display a rendered document with ANSI escape sequences and output a 'Monoid'.------ The annotations are mapped to a @[SetStyle]@ array.-displayStyleCode :: Monoid o => (String -> o) -> (a -> [SetStyle]) -> Term -> SimpleDoc a -> o-displayStyleCode f g t d = runStyle t $- mappend <$>- displayDecoratedA push pop str d <*>- (f <$> applyStyleCode)- where push x = changeStyle (Save:g x) >> pure mempty- pop _ = changeStyle [Restore] >> pure mempty- str s = f . (`mappend` s) <$> applyStyleCode- -- | Display a rendered document with ANSI escape sequences and output a 'ShowS' function. ----- The annotations are mapped to a '[SetStyle]' array.-displayStyleCodeS :: (a -> [SetStyle]) -> Term -> SimpleDoc a -> ShowS-displayStyleCodeS f term = (++) . displayStyleCode id f term+-- The annotations are mapped to a '[Colored a]' array.+displayColoredS :: (a -> [Colored String]) -> Term -> SimpleDoc a -> ShowS+displayColoredS f term = showColoredS term . displayColored id f -- | Display a rendered document with ANSI escape sequences and output 'Text'. ----- The annotations are mapped to a '[SetStyle]' array.-displayStyleCodeT :: (a -> [SetStyle]) -> Term -> SimpleDoc a -> TL.Text-displayStyleCodeT f term = TL.toLazyText . displayStyleCode TL.fromString f term+-- The annotations are mapped to a '[Colored TL.Builder]' array.+displayColoredT :: (a -> [Colored TL.Builder]) -> Term -> SimpleDoc a -> TL.Text+displayColoredT f term = TL.toLazyText . showColored id TL.fromString term . displayColored TL.fromString f --- | Display a rendered document with ANSI escape sequences to a given 'Handle'.+-- | Display a rendered document with ANSI escape sequences and output 'ByteString'. ----- The annotations are mapped to a '[SetStyle]' array.-hDisplayStyle :: MonadIO m => Handle -> (a -> [SetStyle]) -> SimpleDoc a -> m ()-hDisplayStyle h f d = hRunWithStyle h [] $- displayDecoratedA push pop str d >> applyStyle- where push x = changeStyle (Save:f x)- pop _ = changeStyle [Restore]- str s = applyStyle >> liftIO (hPutStr h s)+-- The annotations are mapped to a '[Colored BL.Builder]' array.+displayColoredB :: (a -> [Colored BL.Builder]) -> Term -> SimpleDoc a -> BL.ByteString+displayColoredB f term = BL.toLazyByteString . showColored id BL.stringUtf8 term . displayColored BL.stringUtf8 f --- | Display a rendered document with ANSI escape sequences to 'stdout'.+-- | Display a rendered document with ANSI escape sequences and output a 'Colored' array. ----- The annotations are mapped to a '[SetStyle]' array.-displayStyle :: MonadIO m => (a -> [SetStyle]) -> SimpleDoc a -> m ()-displayStyle = hDisplayStyle stdout+-- The annotations are mapped to a 'Colored' array.+displayColored :: (String -> o) -> (a -> [Colored o]) -> SimpleDoc a -> [Colored o]+displayColored f g d = displayDecoratedA push pop str d []+ where push = (++) . (Push:) . g+ pop = const (Pop:)+ str = (++) . (:[]) . Value . f --- | The action @(putDocStyle f doc)@ pretty prints @doc@ to 'stdout'+-- | The action @(putDocColored f doc)@ pretty prints @doc@ to 'stdout' -- using the annotations. ----- The annotations are mapped by @f@ to @[SetStyle]@ arrays.-putDocStyle :: (a -> [SetStyle]) -> Doc a -> IO ()-putDocStyle = hPutDocStyle stdout+-- The annotations are mapped by @f@ to 'Colored' arrays.+putDocColored :: Term -> (a -> [Colored String]) -> Doc a -> IO ()+putDocColored = hPutDocColored stdout --- | The action @(hPutDocStyle handle f doc)@ pretty prints @doc@ to file handle @handle@+-- | The action @(hPutDocColored handle f doc)@ pretty prints @doc@ to file handle @handle@ -- using the annotations. ----- The annotations are mapped by @f@ to @[SetStyle]@ arrays.-hPutDocStyle :: Handle -> (a -> [SetStyle]) -> Doc a -> IO ()-hPutDocStyle handle f = hDisplayStyle handle f . renderPrettyDefault+-- The annotations are mapped by @f@ to 'Colored' arrays.+hPutDocColored :: Handle -> Term -> (a -> [Colored String]) -> Doc a -> IO ()+hPutDocColored handle term f = hPrintColored hPutStr handle term . displayColored id f . renderPrettyDefault
wl-pprint-console.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: wl-pprint-console-version: 0.0.1.2+version: 0.1.0.0 synopsis: Wadler/Leijen pretty printer supporting colorful console output. description: Wadler/Leijen pretty printer with support for annotations and colorful console output. Additional useful display routines are provided, e.g, for HTML output. category: Text@@ -29,10 +29,10 @@ ghc-options: -Wall build-depends: base >= 4.8 && < 5- , console-style >= 0.0.2.0 && < 0.1- , wl-pprint-annotated >= 0.0.1.2 && < 0.1- , mtl >= 2.2 && < 2.4+ , colorful-monoids >= 0.1 && < 0.2+ , wl-pprint-annotated >= 0.0.1.2 && < 0.0.2 , text >= 0.11 && < 1.3+ , bytestring >= 0.10.2 && < 0.11 exposed-modules: Text.PrettyPrint.Console.WL default-language: Haskell2010