Document

sealed class Document : PrettyPrintable

Represents a pretty printed document.

More specifically, a Document represents a non-empty set of possible layouts of a document. The print functions select one of these possibilities, taking into account things like the width of the output document.

Documents are created using the invoke functions, but the main interface is through PrettyPrintable.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun print(lineWidth: Int = DEFAULT_LINE_WIDTH): String

Renders the document as a String.

fun print(output: PrintStream, lineWidth: Int = DEFAULT_LINE_WIDTH, ansi: Boolean = false)

Renders this document as a string and writes it to output. Each line of the output will be under lineWidth characters if possible. If ansi is true, ANSI escape codes are output to style the document according to the Style annotations in the document.

Link copied to clipboard
open override fun toDocument(): Document

Returns this object.

Link copied to clipboard
override fun toString(): String

Do not use toString; use print instead.

Extensions

Link copied to clipboard

Like joined but using commas as separators and enclosed in /* and */.

Link copied to clipboard

Concatenates this and other with a line break in between.

operator fun PrettyPrintable.div(other: String): Document

Convenience method. See plus.

Link copied to clipboard

Tries laying out this document into a single line by removing the contained Document.lineBreaks (and replacing them with spaces); if this does not fit the page, the document is laid out without any changes. This function is the key to layouts that adapt to available space nicely.

Link copied to clipboard
fun PrettyPrintable.nested(indentationChange: Int = 4): Document

Returns a new document that is this with the nesting level (indentation after newlines) increased by indentationChange. Negative values for indentationChange are allowed, and decrease the nesting level accordingly.

Link copied to clipboard

Concatenates this and other.

operator fun PrettyPrintable.plus(other: String): Document

Convenience method that automatically converts other to a Document.

Link copied to clipboard

Returns a new document that is this with style applied.

Link copied to clipboard

Concatenates this and other with a space in between.

operator fun PrettyPrintable.times(other: String): Document

Convenience method. See plus.