Published release 0.2.1. Unreleased PR #2 reference.
LOOM 0.2.1 / RENDERING AND LAYOUT
Buffer
Dimensions are clamped to zero or greater at initialization. Direct subscripting requires valid coordinates. Prefer put for clipped writes: it accepts exactly one grapheme and a width of 1 or 2, rejects terminal controls, and never paints half a wide grapheme. Wide trailing cells have width 0 and an empty symbol.
Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.
Example
var buffer = Buffer(width: 8, height: 2)
buffer.put("界", width: 2, at: Point(x: 0, y: 0))
buffer.highlight(at: Point(x: 1, y: 0))
_ = buffer.plainTextMembers on this page
Feature guides and release status
Buffer
struct BufferConforms to: Swift.Sendable, Swift.SendableMetatype.
A rectangular grid of terminal cells with whole-grapheme clipping.
Source · Buffer.swift:4width
let width: IntWidth in terminal cells.
Source · Buffer.swift:5height
let height: IntHeight in terminal cells.
Source · Buffer.swift:6area
var area: Rect { get }The available zero-based rectangle in terminal cells.
Source · Buffer.swift:11plainText
var plainText: String { get }The visible symbols, with explicit newlines between buffer rows.
Source · Buffer.swift:16init(width:height:)
init(width: Int, height: Int)Creates a value with the supplied arguments. Default arguments are shown in the declaration.
Parameters (2)
width- Available columns in terminal cells.
height- Available rows in terminal cells.
subscript(_:_:)
subscript(x: Int, y: Int) -> Cell { get }Accesses a cell at valid, zero-based buffer coordinates.
Parameters (2)
x- Argument type and any default are shown in the declaration; see the behavior notes above.
y- Argument type and any default are shown in the declaration; see the behavior notes above.
Returns Cell.
reset()
mutating func reset()Clears every cell while retaining the allocated buffer.
Source · Buffer.swift:41withClip(_:_:)
mutating func withClip(_ area: Rect, _ draw: (inout Buffer) -> Void)Restricts writes to the intersection of this area and any enclosing clip.
Coordinates remain absolute. Whole graphemes crossing an edge are omitted.
Parameters (2)
area- Assigned absolute terminal-cell rectangle.
draw- Argument type and any default are shown in the declaration; see the behavior notes above.
put(_:width:at:style:link:)
mutating func put(_ symbol: String, width span: Int, at point: Point, style: Style = Style(), link: String? = nil)Writes a whole grapheme or nothing, preventing half-wide characters at a clip edge.
Parameters (5)
symbol- Argument type and any default are shown in the declaration; see the behavior notes above.
width- Available columns in terminal cells.
at- Argument type and any default are shown in the declaration; see the behavior notes above.
style- Text/cell appearance.
link- Argument type and any default are shown in the declaration; see the behavior notes above.
highlight(at:)
mutating func highlight(at point: Point)Highlights the entire grapheme occupying the selected cell.
Parameters (1)
at- Argument type and any default are shown in the declaration; see the behavior notes above.
fill(_:symbol:width:style:link:)
mutating func fill(_ region: Rect, symbol: String = " ", width span: Int = 1, style: Style = Style(), link: String? = nil)Fills complete glyphs inside the region and current clip.
Invalid symbols are rejected by put.
Parameters (5)
region- Argument type and any default are shown in the declaration; see the behavior notes above.
symbol- Argument type and any default are shown in the declaration; see the behavior notes above.
width- Available columns in terminal cells.
style- Text/cell appearance.
link- Argument type and any default are shown in the declaration; see the behavior notes above.
clear(_:)
mutating func clear(_ region: Rect)Clears complete glyphs inside the region and current clip.
Parameters (1)
region- Argument type and any default are shown in the declaration; see the behavior notes above.
apply(_:to:)
mutating func apply(_ patch: StylePatch, to region: Rect)Applies appearance changes only to complete glyphs inside the region and current clip.
Parameters (2)
patch- Argument type and any default are shown in the declaration; see the behavior notes above.
to- Argument type and any default are shown in the declaration; see the behavior notes above.
copy(from:region:to:)
mutating func copy(from source: Buffer, region: Rect, to destination: Point)Copies complete source glyphs to a destination origin, retaining styles and links.
Value semantics make copies from this buffer safe even when source and destination overlap.
Parameters (3)
from- Argument type and any default are shown in the declaration; see the behavior notes above.
region- Argument type and any default are shown in the declaration; see the behavior notes above.
to- Argument type and any default are shown in the declaration; see the behavior notes above.
compose(_:at:)
mutating func compose(_ source: Buffer, at destination: Point = Point(x: 0, y: 0))Composes the complete source grid at the supplied destination origin.
Parameters (2)
source- Argument type and any default are shown in the declaration; see the behavior notes above.
at- Argument type and any default are shown in the declaration; see the behavior notes above.
resized(width:height:preservingContents:)
func resized(width: Int, height: Int, preservingContents: Bool = true) -> BufferReturns a resized grid, optionally retaining complete glyphs in the shared area.
Parameters (3)
width- Available columns in terminal cells.
height- Available rows in terminal cells.
preservingContents- Argument type and any default are shown in the declaration; see the behavior notes above.
Returns Buffer.
resize(width:height:preservingContents:)
mutating func resize(width: Int, height: Int, preservingContents: Bool = true)Resizes the grid.
Existing glyphs crossing the new edge are omitted.
Parameters (3)
width- Available columns in terminal cells.
height- Available rows in terminal cells.
preservingContents- Argument type and any default are shown in the declaration; see the behavior notes above.
differences(from:)
func differences(from previous: Buffer) -> [BufferDifference]Returns cell-level changes, including removed cells and wide-glyph continuation cells.
Parameters (1)
from- Argument type and any default are shown in the declaration; see the behavior notes above.
Returns [BufferDifference].