Zafu/Text/Prettysource code:
public dependencies: Zafu/Abstract/Monoid, Zafu/Collection/LazyList
Doc, Documentaligned, ansi_control, append, append_line, append_line_or_space,
append_line_or_space_text,
append_line_text, append_space, append_space_text, append_text, bracket_by, by, cat, char, comma, document_Bool, document_Char, document_Float64, document_Int, document_List, document_Option, document_String, document_Unit, document_from_fn, empty, fill, flatten, flatten_option, float, fold_docs, grouped, hang, hard_line, indent, int, intercalate, is_empty, line, line_break, line_or, line_or_empty, line_or_space, max_width, monoid_Doc, nested, non_empty, paragraph, prepend_text, render, render_String, render_stream, render_stream_trim, render_trim, render_wide_stream, repeat, representation, space, spaces, split, spread, stack, tabulate, tabulate_with, text, text_with_line, tight_bracket_by, to_Doc, unzero, zero_widthDoctype Doc
Document[a]Typeclass-style dictionary for rendering a values into
Doc. Input: to_doc_fn converts one
a value to a document. Output: a reusable renderer instance
for type a.
type Document[a: -*]
alignedAligns doc to the current rendering column. Input: any
document. Output: aligned document node.
references: Doc
def aligned(doc: Doc) -> Doc
ansi_controlBuilds ANSI escape output as zero-width control text. Input: list of
numeric ANSI codes. Output: zero-width
\u001b[<codes>m sequence.
def ansi_control(codes: List[Int]) -> Doc
appendConcatenates two documents in O(1). Input: left and right documents. Output: combined document preserving both layouts.
references: Doc
def append(left: Doc, right: Doc) -> Doc
append_lineConcatenates with a soft line break between operands. Input: left and
right documents. Output: left + line + right.
references: Doc
def append_line(left: Doc, right: Doc) -> Doc
append_line_or_spaceConcatenates with line_or_space between operands. Input:
left and right documents. Output:
left + line_or_space + right.
references: Doc
def append_line_or_space(left: Doc, right: Doc) -> Doc
append_line_or_space_textConcatenates with line_or_space before text. Input: left
document and right string. Output:
left + line_or_space + text(right).
def append_line_or_space_text(left: Doc, right: String) -> Doc
append_line_textConcatenates with a soft line break before text. Input: left document
and right string. Output: left + line + text(right).
def append_line_text(left: Doc, right: String) -> Doc
append_spaceConcatenates with a space between operands. Input: left and right
documents. Output: left + space + right.
references: Doc
def append_space(left: Doc, right: Doc) -> Doc
append_space_textConcatenates with a space before text. Input: left document and right
string. Output: left + space + text(right).
def append_space_text(left: Doc, right: String) -> Doc
append_textAppends plain text after doc. Input: document prefix and
string suffix. Output: doc followed by
text(value).
def append_text(doc: Doc, value: String) -> Doc
bracket_byWraps doc between left and
right with soft line spacing. Input: body doc, left
delimiter, right delimiter, and nesting amount. Output: grouped
bracketed document.
def bracket_by(doc: Doc, left: Doc, right: Doc, amount: Int) -> Doc
byContramap/project combinator for Document. Input:
renderer for b and projection from a to
b. Output: renderer for a.
references: Document
def by[a, b](docu: Document[a], project: b -> a) -> Document[b]
catConcatenates docs with no separator. Input: list of docs. Output: all docs appended in order.
def cat(docs: List[Doc]) -> Doc
charConverts one character to a document. Input: a character value.
Output: line when the character is newline, otherwise a
single-character text doc.
def char(value: Char) -> Doc
commaComma text document. Output: a one-character comma
Doc.
references: Doc
comma: Doc
document_BoolBuilt-in Document for Bool. Output:
True or False.
document_Bool: Document[Bool]
document_CharBuilt-in Document for Char. Output: uses
char.
document_Char: Document[Char]
document_Float64Built-in Document for Float64. Output: uses
float.
document_Float64: Document[Float64]
document_IntBuilt-in Document for Int. Output: uses
int.
document_Int: Document[Int]
document_ListBuilds a Document instance for lists. Input: item
renderer. Output: bracketed list document using
fill(comma + line, ...).
def document_List[a](item_doc: Document[a]) -> Document[List[a]]
document_OptionBuilds a Document instance for options. Input: item
renderer. Output: None or grouped
Some(<item>).
def document_Option[a](item_doc: Document[a]) -> Document[Option[a]]
document_StringBuilt-in Document for String. Output: uses
text.
document_String: Document[String]
document_UnitBuilt-in Document for Unit. Output: literal
().
document_Unit: Document[()]
document_from_fnBuilds a Document[a] from a rendering function. Input:
function from a to Doc. Output:
Document[a] dictionary.
def document_from_fn[a](fn: a -> Doc) -> Document[a]
emptyThe empty document. Output: renders as the empty string and acts as append identity.
references: Doc
empty: Doc
fillWidth-sensitive separator folding like Paiges fill.
Input: separator doc and item docs. Output: document that packs items
onto lines when possible.
def fill(sep: Doc, docs: List[Doc]) -> Doc
flattenFlattens all FlatAlt/Union behavior to
single-line alternatives. Input: any document. Output: flattened
document.
references: Doc
def flatten(doc: Doc) -> Doc
flatten_optionAttempts to flatten doc and returns None
when flattening is a no-op. Input: any document. Output:
Some(flat_doc) if structure changes, else
None.
def flatten_option(doc: Doc) -> Option[Doc]
floatRenders a float with deterministic parseable output. Input: a
Float64. Output: NaN, Infinity,
-Infinity, or the runtime shortest round-trippable
decimal.
def float(value: Float64) -> Doc
fold_docsReduces docs from left to right using fn.
Input: list of docs and a binary combine function. Output: reduced
document, or empty for an empty list.
def fold_docs(docs: List[Doc], fn: (Doc, Doc) -> Doc) -> Doc
groupedAdds an optimistic flat layout branch for doc. Input: a
document with potential line breaks. Output: doc wrapped in
Union(flatten(doc), doc) when flattening changes it.
references: Doc
def grouped(doc: Doc) -> Doc
hangApplies nested and then aligned. Input:
document and indent amount. Output: hanging-indented document.
def hang(doc: Doc, amount: Int) -> Doc
hard_lineMandatory line break. Output: always renders as newline plus current indentation.
references: Doc
hard_line: Doc
indentPrefixes doc with amount spaces and hangs
subsequent lines. Input: document and indent amount. Output: indented
document.
def indent(doc: Doc, amount: Int) -> Doc
intRenders an integer in canonical base-10 form. Input: an
Int. Output: decimal text with optional leading
-.
def int(value: Int) -> Doc
intercalateInserts sep between each document in docs.
Input: separator doc and items. Output: concatenated document with
separator between neighbors.
def intercalate(sep: Doc, docs: List[Doc]) -> Doc
is_emptyChecks whether doc has no visible output. Input: any
document. Output: True only when rendering produces no text
or line breaks.
def is_empty(doc: Doc) -> Bool
lineSoft line break that becomes a space in flattened layouts. Output:
newline in broken mode, " " in flat mode.
references: Doc
line: Doc
line_breakSoft line break that disappears in flattened layouts. Output: newline in broken mode, empty in flat mode.
references: Doc
line_break: Doc
line_orChooses between a real line break and flattened doc.
Input: fallback document used in flat mode. Output: document that
renders as newline or flattened fallback based on grouping.
references: Doc
def line_or(doc: Doc) -> Doc
line_or_emptyLine-or-empty convenience value. Output: newline in broken layouts, empty in flat layouts.
references: Doc
line_or_empty: Doc
line_or_spaceLine-or-space convenience value. Output: newline in broken layouts, space in flat layouts.
references: Doc
line_or_space: Doc
max_widthComputes the maximum rendered line width of doc. Input:
any document. Output: maximum column width reached across all lines.
def max_width(doc: Doc) -> Int
monoid_DocMonoid on Doc where append is the combine
references: Doc, Zafu/Abstract/Monoid::Monoid
monoid_Doc: Zafu/Abstract/Monoid::Monoid[Doc]
nestedIncreases indentation level for doc. Input: document and
indent amount. Output: a nested document with added indentation.
def nested(doc: Doc, amount: Int) -> Doc
non_emptyNegation of is_empty. Input: any document. Output:
True when doc has visible output.
def non_empty(doc: Doc) -> Bool
paragraphAlias for split. Input: source string paragraph. Output:
reflowable paragraph document.
def paragraph(value: String) -> Doc
prepend_textPrepends plain text before doc. Input: string prefix and
document suffix. Output: text(value) followed by
doc.
def prepend_text(value: String, doc: Doc) -> Doc
renderRenders doc at width. Input: document and
target width. Output: lazy chunk stream in rendering order.
references: Doc, Int, String, Zafu/Collection/LazyList::LazyList
def render(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]
render_Stringdef render_String(doc: Doc, width: Int) -> String
render_streamRenders doc to a stream of chunks with bounded layout
selection. Input: document and target width. Output: lazy chunk stream
whose concatenation is the rendered text.
references: Doc, Int, String, Zafu/Collection/LazyList::LazyList
def render_stream(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]
render_stream_trimChunk-stream form of render_trim. Input: document and
target width. Output: lazy chunk stream containing trimmed rendering
output.
references: Doc, Int, String, Zafu/Collection/LazyList::LazyList
def render_stream_trim(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]
render_trimRenders doc and trims trailing spaces on each line.
Input: document and target width. Output: lazy chunk stream with
right-trimmed lines.
references: Doc, Int, String, Zafu/Collection/LazyList::LazyList
def render_trim(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]
render_wide_streamRenders without bounded fits checks (always picks
flattened union branch). Input: document. Output: lazy chunk stream
rendered in wide mode.
references: Doc, String, Zafu/Collection/LazyList::LazyList
def render_wide_stream(doc: Doc) -> Zafu/Collection/LazyList::LazyList[String]
repeatRepeats doc count times using a logarithmic
doubling strategy. Input: document doc and repeat count
count. Output: empty for non-positive counts,
else left-associated repetition of doc.
def repeat(doc: Doc, count: Int) -> Doc
representationReturns a structural debug representation of doc. Input:
any document. Output: text document describing internal node
structure.
references: Doc
def representation(doc: Doc) -> Doc
spaceSingle space text document. Output: a one-character space
Doc.
references: Doc
space: Doc
spacesCreates a document containing width spaces. Input:
number of spaces to emit. Output: repeat(space, width).
def spaces(width: Int) -> Doc
splitSplits text into words and rejoins with line_or_space.
Input: source string with arbitrary whitespace. Output: reflowable
paragraph document.
def split(value: String) -> Doc
spreadConcatenates docs separated by space. Input: list of
docs. Output: space-separated document.
def spread(docs: List[Doc]) -> Doc
stackConcatenates docs separated by line. Input: list of
docs. Output: line-separated document.
def stack(docs: List[Doc]) -> Doc
tabulateConvenience tabulate_with using space fill and empty key
suffix. Input: (key, doc) rows. Output: aligned table
document.
references: Doc, List, String, Tuple2
def tabulate(rows: List[(String, Doc)]) -> Doc
tabulate_withBuilds aligned key/value rows with configurable fill character and
key suffix. Input: key fill character, right-side separator text, and
(key, doc) rows. Output: multi-line aligned table
document.
references: Char, Doc, List, String, Tuple2
def tabulate_with(fill_char: Char, right_sep: String, rows: List[(String, Doc)]) -> Doc
textConverts value into a Doc where
\n uses line. Input: any string, including
embedded newlines. Output: a width-sensitive document equivalent to
text_with_line(value, line).
def text(value: String) -> Doc
text_with_line+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+
Exported constructors and combinators
+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+
Converts value into a Doc, replacing each
\n with line_doc. Input: value
string and line_doc separator used between split lines.
Output: concatenated document preserving empty leading/trailing
lines.
def text_with_line(value: String, line_doc: Doc) -> Doc
tight_bracket_byWraps doc between left and
right without flat-mode interior spaces. Input: body doc,
left delimiter, right delimiter, and nesting amount. Output: grouped
tightly bracketed document.
def tight_bracket_by(doc: Doc, left: Doc, right: Doc, amount: Int) -> Doc
to_DocApplies a Document[a] renderer to one value. Input:
document dictionary and item value. Output: rendered Doc
for that value.
def to_Doc[a](docu: Document[a], value: a) -> Doc
unzeroRemoves all zero-width nodes from doc. Input: any
document. Output: document with ZeroWidth replaced by
empty.
references: Doc
def unzero(doc: Doc) -> Doc
zero_widthInserts zero-width text into output. Input: value bytes
to emit without affecting layout width. Output: empty when
value is empty, else a zero-width node.
def zero_width(value: String) -> Doc