HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduledoclayout-0.6Haskell2010

Text.DocLayout

A prettyprinting library for the production of text documents, including wrapped text, indentation and other prefixes, and blocks for tables.

Contents
  1. Rendering
  2. Doc constructors
  3. Functions for concatenating documents
  4. Functions for querying documents
  5. Char properties
  6. Types
Synopsis
  • Packagedoclayout-0.6
  • Exports70
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceDocLayout.hs

Rendering

valuerenderPlain :: HasChars a => Maybe Int -> Doc a -> a

Render a Doc without using ANSI escapes. renderPlain (Just n) will use a line length of n to reflow text on breakable spaces. renderPlain Nothing will not reflow text.

valuerenderANSI :: HasChars a => Maybe Int -> Doc a -> Text

Render a Doc with ANSI escapes. renderANSI (Just n) will use a line length of n to reflow text on breakable spaces. renderANSI Nothing will not reflow text.

Doc constructors

valuecr :: Doc a

A carriage return. Does nothing if we're at the beginning of a line; otherwise inserts a newline.

valueblankline :: Doc a

Inserts a blank line unless one exists already. (blankline <> blankline has the same effect as blankline.

valueblanklines :: Int -> Doc a

Inserts blank lines unless they exist already. (blanklines m <> blanklines n has the same effect as blanklines (max m n).

valueprefixed :: IsString a => String -> Doc a -> Doc a

Uses the specified string as a prefix for every line of the inside document (except the first, if not at the beginning of the line).

valuehang :: IsString a => Int -> Doc a -> Doc a -> Doc a

A hanging indent. hang ind start doc prints start, then doc, leaving an indent of ind spaces on every line but the first.

valueafterBreak :: Text -> Doc a

Content to print only if it comes at the beginning of a line, to be used e.g. for escaping line-initial . in roff man.

valuelblock :: HasChars a => Int -> Doc a -> Doc a

lblock n d is a block of width n characters, with text derived from d and aligned to the left.

valuevfill :: HasChars a => a -> Doc a

An expandable border that, when placed next to a box, expands to the height of the box. Strings cycle through the list provided.

Functions for concatenating documents

value(<+>) :: Doc a -> Doc a -> Doc a

Concatenate a list of Docs, putting breakable spaces between them.

value($+$) :: Doc a -> Doc a -> Doc a

a $+$ b puts a above b, with a blank line between.

Functions for querying documents

valuecharWidth :: Char -> Int

Returns width of a character in a monospace font: 0 for a combining character, 1 for a regular character, 2 for an East Asian wide character. Ambiguous characters are treated as width 1.

valuerealLength :: HasChars a => a -> Int

Get real length of string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 1.

Get the real length of a string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 2.

Char properties

Types

datadata Doc a

Document, including structure relevant for layout.

Constructors

Instances13Functor, Foldable, Traversable, Eq, Data, Ord, …
classclass (IsString a, Semigroup a, Monoid a, Show a) => HasChars a where

Class abstracting over various string types that can fold over characters. Minimal definition is foldrChar and foldlChar, but defining the other methods can give better performance.

Methods

Instances5HasChars
newtypenewtype Attributed a

A sequence of strings with font attributes.

Instances14Functor, Foldable, Traversable, Eq, Data, Ord, …