Community
Modules 28

Data.Text.Prettyprint.Doc.Render.Text

Use \ Prettyprinter.Render.Text\ instead.

module Prettyprinter.Render.Text prettyprinter-1.7.2 · 5 declarations

hPutDoc :: Handle -> Doc ann -> IO ()

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)

putDoc :: Doc ann -> IO ()

(putDoc doc) prettyprints document doc to standard output. Uses the defaultLayoutOptions.

>>> putDoc ("hello" <+> "world")
hello world
'putDoc' = 'hPutDoc' 'stdout'

renderIO :: Handle -> SimpleDocStream ann -> IO ()

(renderIO h sdoc) writes sdoc to the file h.

>>> renderIO System.IO.stdout (layoutPretty defaultLayoutOptions "hello\nworld")
hello
world

This function is more efficient than hPutStr h (renderStrict sdoc), since it writes to the handle directly, skipping the intermediate Text representation.

renderLazy :: SimpleDocStream ann -> TL.Text

(renderLazy sdoc) takes the output 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

(renderStrict sdoc) takes the output sdoc from a rendering function and transforms it to strict text.

Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 21 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 19f659e0fd2a9606431ae6a3ec65f9ace725052e19ca6a9f9e9f2759e30fd129

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.