A pretty printing library based on Wadler's paper "A Prettier Printer". It has been enhanced with support for ANSI terminal colored output using the ansi-terminal package.
This package is extensively based on Daan Leijen's excellent wl-pprint library.
The latest version of the example is always available online:
module Main (main) where
import Text.PrettyPrint.ANSI.Leijen
import System.IO
main :: IO ()
main = do
-- Going directly to the console is portable across Unix and Windows...
putDoc $ red (text "Red") <> comma <+> white (text "white") <+> text "and"
<+> blue (text "blue") <> char '!' <> linebreak
putDoc $ blue (text "Nested" <+> dullyellow (text "colors") <+> text "example")
<> linebreak
hPutDoc stdout $ onred (text "Red") <> comma <+> onwhite (text "white") <+>
text "and" <+> onblue (text "blue") <> char '!' <> linebreak
hPutDoc stdout $ onblue (text "Nested" <+> ondullyellow (text "colors")
<+> text "example") <> linebreak
-- ...but going via a string will only preserve formatting information on Unix
putStr $ show $ green (text ("I will be green on Unix but uncolored " ++
"on Windows")) <> linebreak
-- Let's see some non-color formatting:
putDoc $ text "We can do" <+> bold (text "boldness") <> text (", if your " ++
"terminal supports it, and even perhaps")
<+> underline (text "underlining")
Haddock documentation is available at Hackage.
Install with Cabal:
$ sudo cabal install ansi-wl-pprint
You can report a bug online.
Other enquiries can be directed to me via email