Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.
LOOM Unreleased (PR #2) / RENDERING AND LAYOUT
Buffer
Mutable clipped terminal-cell grid. Ordinary put validates one grapheme with width one or two, filters controls, and preserves complete glyphs. Explicit forced-width puts accept safe multi-grapheme payloads only when the positive declared width fits. Region copy/composition/styles and diff policies preserve whole footprints; policies do not permit raw escape payloads.
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:diffPolicy:)
mutating func put(_ symbol: String, width span: Int, at point: Point, style: Style = Style(), link: String? = nil, diffPolicy: CellDiffPolicy = .automatic)Writes a whole grapheme or nothing, preventing half-wide characters at a clip edge.
With .forcedWidth(span), accepts multiple safe graphemes occupying that explicit
positive span. The caller owns terminal width accuracy; Unicode layout is unchanged.
Parameters (6)
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.
diffPolicy- 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.
setDiffPolicy(_:in:)
mutating func setDiffPolicy(_ policy: CellDiffPolicy, in region: Rect)Sets presentation policy for complete glyphs inside the region and current clip.
Copies retain the policy; subsequent writes replace it with their own policy.
Skipped cells survive ordinary frame painting, but explicit clears and scrolling
still affect their terminal area. A forced width must match each existing glyph's
stored span; mismatched glyphs are unchanged. Use put to create a new span.
Parameters (2)
policy- Argument type and any default are shown in the declaration; see the behavior notes above.
in- 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].