Documentation
¶
Overview ¶
Package doc is a small Wadler/Prettier-style document algebra: you build an immutable layout tree out of Text, Concat, Group, Indent, and the line primitives, then Render it at a target width. A Group lays its contents out on one line when they fit and breaks them across lines when they don't, so callers describe structure and let the renderer own wrapping.
Documents are immutable values: every constructor returns a fresh Doc and none of them retain or mutate their arguments, so a Doc is safe to share and reuse.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc is an immutable layout document. The zero value renders as empty text. Fields are ordered so the garbage collector's pointer-scan prefix is as short as possible.
func Group ¶
Group renders d flat (every Line a space, every Softline empty) when it fits the remaining width, and broken (every line primitive a newline) when it doesn't. A Hardline anywhere inside forces the broken layout.
func Hardline ¶
func Hardline() Doc
Hardline always renders as a newline and forces every enclosing Group to break.
func Indent ¶
Indent renders d one indentation step deeper, which only shows up on the lines that follow a break inside d.
func Line ¶
func Line() Doc
Line renders as a single space when its group is flat and as a newline when the group is broken.