loom & weft
Made for Swift.

Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.

LOOM Unreleased (PR #2) / RENDERING AND LAYOUT

Terminal

Describe the whole logical screen in every draw closure. Each draw starts with a cleared frame and no cursor. The first draw, a resize, or invalidation forces a repaint. Unchanged cells and cursor emit no bytes. A failed backend write propagates its error and forces the next draw to repaint. Output settings are explicit; environment capabilities are not inferred automatically.

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 terminal = Terminal(backend: ANSIBackend(), width: 80, height: 24)
let stats = try terminal.draw { frame in
    frame.render(Paragraph(TextLayout("Hello", width: frame.area.width)), in: frame.area)
}
_ = stats.bytes
Members on this page

Feature guides and release status

Terminal

Structure
struct Terminal<B> where B : Backend

ANSI terminal rendering over a weft byte sink.

This compatible facade shares viewport and failure behavior with RenderTerminal. The caller owns terminal modes and input reading.

Source · Terminal.swift:7

backend

Instance Property
var backend: B { get }

The output backend retained by the terminal; externally read-only.

Source · Terminal.swift:10

viewport

Instance Property
var viewport: Viewport { get }

Available terminal-cell viewport.

Source · Terminal.swift:11

viewportArea

Instance Property
var viewportArea: Rect { get }

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Terminal.swift:12

requiresReanchor

Instance Property
var requiresReanchor: Bool { get }

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Terminal.swift:13

snapshot

Instance Property
var snapshot: FrameSnapshot? { get }

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Terminal.swift:14

localPoint(from:)

Instance Method
func localPoint(from physicalPoint: Point) -> Point?

Maps a physical terminal cell inside the active viewport into frame-local coordinates; returns nil outside it.

Parameters (1)
from
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Point?.

Source · Terminal.swift:28

physicalPoint(from:)

Instance Method
func physicalPoint(from localPoint: Point) -> Point?

Maps a valid local frame cell to physical terminal coordinates; returns nil outside it.

Parameters (1)
from
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Point?.

Source · Terminal.swift:29

resize(width:height:)

Instance Method
mutating func resize(width: Int, height: Int)

Replaces both buffers and forces a full repaint when dimensions change. A call with unchanged dimensions does nothing.

Parameters (2)
width
Available columns in terminal cells.
height
Available rows in terminal cells.
Source · Terminal.swift:30

setViewport(_:)

Instance Method
mutating func setViewport(_ viewport: Viewport)

Changes viewport policy and invalidates placement. Inline viewports require a confirmed physical anchor.

Parameters (1)
viewport
Available terminal-cell viewport.
Source · Terminal.swift:31

reanchor(at:)

Instance Method Throws
mutating func reanchor(at anchor: Point) throws

Confirms a new physical inline anchor after uncertain scrolling; throws if the viewport is not inline.

Parameters (1)
at
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Terminal.swift:32

invalidate()

Instance Method
mutating func invalidate()

Invalidates rendering assumptions after external output. Inline scrolling uncertainty may require explicit reanchoring.

Source · Terminal.swift:33

draw(_:)

Instance Method Throws
@discardableResult mutating func draw(_ render: (inout Frame) -> Void) throws -> RenderStats

Clears and rebuilds the complete logical frame, encodes changes, writes nonempty output, and returns RenderStats. Throws the backend write error; the next draw then performs a full repaint.

Parameters (1)
render
Closure that builds the complete next logical frame.

Returns RenderStats.

Source · Terminal.swift:36

insertBefore(_:)

Instance Method Throws
mutating func insertBefore(_ content: Buffer) throws

Inserts transcript cells before the retained inline frame, then repaints it. Requires inline placement; failed uncertain scrolling requires reanchoring and must not be blindly replayed.

Parameters (1)
content
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Terminal.swift:40

insertBefore(height:render:)

Instance Method Throws
mutating func insertBefore(height: Int, render: (inout Frame) -> Void) throws

Builds full-width transcript rows with the supplied closure and inserts them before the retained inline frame.

Parameters (2)
height
Available rows in terminal cells.
render
Closure that builds the complete next logical frame.
Source · Terminal.swift:41