Module

Dodo

#indent

indent :: forall a. Doc a -> Doc a

Increases the indentation level by one indent.

#align

align :: forall a. Int -> Doc a -> Doc a

Increases the indentation level by the number of spaces (for alignment purposes).

#alignCurrentColumn

alignCurrentColumn :: forall a. Doc a -> Doc a

Increases the indentation level so that it aligns to the current column.

#annotate

annotate :: forall a. a -> Doc a -> Doc a

Adds an annotation to a document. Printers can interpret annotations to style their output, eg. ANSI colors.

#withPosition

withPosition :: forall a. (Position -> Doc a) -> Doc a

Build a document based on the current layout position.

#text

text :: forall a. String -> Doc a

The most basic document leaf. This should not contain newlines. If it does your document will look very funny.

#break

break :: forall a. Doc a

Inserts a hard line break.

#spaceBreak

spaceBreak :: forall a. Doc a

Inserts a space when in a flex group, otherwise inserts a break.

#softBreak

softBreak :: forall a. Doc a

Inserts nothing when in a flex group, otherwise inserts a break.

#space

space :: forall a. Doc a

A singe space character.

#lines

lines :: forall f a. Foldable f => f (Doc a) -> Doc a

Appends documents with a break in between them.

#words

words :: forall f a. Foldable f => f (Doc a) -> Doc a

Appends documents with a space in between them.

#(<%>)

Operator alias for Dodo.appendBreak (right-associative / precedence 1)

#(<+>)

Operator alias for Dodo.appendSpace (right-associative / precedence 2)

#(</>)

Operator alias for Dodo.appendSpaceBreak (left-associative / precedence 2)

#appendBreak

appendBreak :: forall a. Doc a -> Doc a -> Doc a

Appends two documents with a break between them.

#appendSpace

appendSpace :: forall a. Doc a -> Doc a -> Doc a

Appends two documents with a space between them.

#appendSpaceBreak

appendSpaceBreak :: forall a. Doc a -> Doc a -> Doc a

Appends two documents with a space between them, falling back to a break if that does not fit.

#flexAlt

flexAlt :: forall a. Doc a -> Doc a -> Doc a

Attempts to layout the first document when in a flex group, falling back to the second as a default.

#flexGroup

flexGroup :: forall a. Doc a -> Doc a

Attempts to layout the document with flex alternatives, falling back to defaults if it doesn't fit the page width.

#flexSelect

flexSelect :: forall a. Doc a -> Doc a -> Doc a -> Doc a

Attempts to layout the first document with flex alternatives, falling back to defaults if it doesn't fit the page width. If the flex alternatives are used then the second document will be appended, otherwise the third document will be appended.

#paragraph

paragraph :: forall f a. Foldable f => f (Doc a) -> Doc a

Appends documents with a space-break in between them.

#textParagraph

textParagraph :: forall a. String -> Doc a

Constructs a wrapping paragraph from a blob of text. Ignores newlines and multiple spaces.

#enclose

enclose :: forall a. Doc a -> Doc a -> Doc a -> Doc a

Uses an opening and closing document to wrap another document.

example = enclose (text "(") (text ")") (text "inner")

#encloseEmptyAlt

encloseEmptyAlt :: forall a. Doc a -> Doc a -> Doc a -> Doc a -> Doc a

Uses an opening and closing document to wrap another document, falling back when the inner document is empty.

example = encloseEmptyAlt (text "[ ") (text " ]") (text "[]") mempty

#encloseWithSeparator

encloseWithSeparator :: forall f a. Foldable f => Doc a -> Doc a -> Doc a -> f (Doc a) -> Doc a

Uses an opening and closing document, as a well as a separator, to render a series of documents. ``purescript example = encloseWithSeparator (text "[") (text "]") (",") [ text "one", text "two" ]


#foldWithSeparator

foldWithSeparator :: forall f a. Foldable f => Doc a -> f (Doc a) -> Doc a

Appends a series of documents together with a separator in between them.

#foldWith

foldWith :: forall f a. Foldable f => (Doc a -> Doc a -> Doc a) -> f (Doc a) -> Doc a

Appends a series of documents together with a given append function. This is notable because it ignores empty documents.

#print

print :: forall b a r. Printer b a r -> PrintOptions -> Doc a -> r

Prints a documents given a printer and print options.

print plainText twoSpaces myDoc

This will use full line-lookahead from the start of a flex group. If it encounters a break or content overflows the page-width, it will layout the group using flex alternative defaults instead.

#Printer

newtype Printer buff ann res

Custom printers can be used to render richer documents than just plain text.

  • emptyBuffer - The initial buffer.
  • writeText - Should write a string with the given width to the buffer.
  • writeIndent - Should write indentation with the given width to the buffer.
  • writeBreak - Should write a line break to the buffer.
  • enterAnnotation - Called when entering a new annotated region. Provides the full annotation stack.
  • leaveAnnotation - Called when leaving an annotated region. Provides the full annotation stack.
  • flushBuffer - Called at the end of the document to get the final result.

Constructors

  • Printer { emptyBuffer :: buff, enterAnnotation :: ann -> List ann -> buff -> buff, flushBuffer :: buff -> res, leaveAnnotation :: ann -> List ann -> buff -> buff, writeBreak :: buff -> buff, writeIndent :: Int -> String -> buff -> buff, writeText :: Int -> String -> buff -> buff }

#plainText

plainText :: forall a. Printer String a String

A plain text printer. Can be used with any document.

#PrintOptions

type PrintOptions = { indentUnit :: String, indentWidth :: Int, pageWidth :: Int, ribbonRatio :: Number }

Configuration options for the printer.

  • pageWidth - The printer will try not to exceed this width on any given line.
  • ribbonRatio - Ratio between 0.0 and 1.0, defaults to 1.0. The printer will use this ratio to calculate the printable area between the current indentation level and the pageWidth.
  • indentUnit - The string used for a single indent.
  • indentWidth - The assumed character width of a single indentUnit.

#twoSpaces

twoSpaces :: PrintOptions

Prints 2-space indents, with a default 80-column page width.

#fourSpaces

fourSpaces :: PrintOptions

Prints 4-space indents, with a default 120-column page width.

#tabs

tabs :: PrintOptions

Prints tab indents (4-wide), with a default 120-column page width.

Re-exports from Dodo.Internal

#Position

type Position = { column :: Int, indent :: Int, line :: Int, nextIndent :: Int, pageWidth :: Int, ribbonWidth :: Int }

Document lines and columns are 0-based offsets.

#Doc

data Doc a

Documents are built using <> as horizontal, line-wise concatenation. The functions in this module let you build documents that respond well to width constraints (such as flexGroup and flexAlt).

Instances

#notEmpty

notEmpty :: forall a. (Doc a -> Doc a) -> Doc a -> Doc a

Only applies the provided function if the document is non-empty.

#isEmpty

isEmpty :: forall a. Doc a -> Boolean

Checks whether the document is empty.

#bothNotEmpty

bothNotEmpty :: forall a. (Doc a -> Doc a -> Doc a) -> Doc a -> Doc a -> Doc a

Only applies the provided function if both documents are non-empty, otherwise just yields whichever is non-empty.

Modules