Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Render an unannotated
SimpleDocStream
as plain
Text
.
Synopsis
- renderLazy :: SimpleDocStream ann -> Text
- renderStrict :: SimpleDocStream ann -> Text
- renderIO :: Handle -> SimpleDocStream ann -> IO ()
- putDoc :: Doc ann -> IO ()
- hPutDoc :: Handle -> Doc ann -> IO ()
Conversion to plain
Text
renderLazy :: SimpleDocStream ann -> Text Source #
(
takes the output
renderLazy
sdoc)
sdoc
from a rendering function
and transforms it to lazy text.
>>>
let render = TL.putStrLn . renderLazy . layoutPretty defaultLayoutOptions
>>>
let doc = "lorem" <+> align (vsep ["ipsum dolor", parens "foo bar", "sit amet"])
>>>
render doc
lorem ipsum dolor (foo bar) sit amet
renderStrict :: SimpleDocStream ann -> Text Source #
(
takes the output
renderStrict
sdoc)
sdoc
from a rendering function
and transforms it to strict text.
Render to a
Handle
renderIO :: Handle -> SimpleDocStream ann -> IO () Source #
(
writes
renderIO
h sdoc)
sdoc
to the file
h
.
>>>
renderIO System.IO.stdout (layoutPretty defaultLayoutOptions "hello\nworld")
hello world
This function is more efficient than
,
since it writes to the handle directly, skipping the intermediate
hPutStr
h (
renderStrict
sdoc)
Text
representation.
Convenience functions
putDoc :: Doc ann -> IO () Source #
(
prettyprints document
putDoc
doc)
doc
to standard output. Uses the
defaultLayoutOptions
.
>>>
putDoc ("hello" <+> "world")
hello world
putDoc
=hPutDoc
stdout
hPutDoc :: Handle -> Doc ann -> IO () Source #
Like
putDoc
, but instead of using
stdout
, print to a user-provided
handle, e.g. a file or a socket. Uses the
defaultLayoutOptions
.
main =withFile
filename (h ->hPutDoc
h doc) where doc =vcat
["vertical", "text"] filename = "someFile.txt"
hPutDoc
h doc =renderIO
h (layoutPretty
defaultLayoutOptions
doc)