loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / RENDERING, VIEWPORTS, AND COMPOSITION

RenderTerminal

Immediate rendering with viewport-local frames and physical terminal output.

The caller owns raw mode, primary/alternate-screen choice, and input reading.

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 = RenderTerminal(backend: TestBackend(width: 20, height: 4), width: 20, height: 4)
try terminal.draw { frame in frame.render(Panel(title: "Test"), in: frame.area) }
_ = terminal.backend.screen
Members on this page

Feature guides and release status

RenderTerminal

Structure
struct RenderTerminal<R> where R : RenderBackend

Immediate rendering with viewport-local frames and physical terminal output.

The caller owns raw mode, primary/alternate-screen choice, and input reading.

Source · RenderTerminal.swift:7

backend

Instance Property
var backend: R { get }

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

Source · RenderTerminal.swift:8

viewport

Instance Property
var viewport: Viewport { get }

Available terminal-cell viewport.

Source · RenderTerminal.swift:9

viewportArea

Instance Property
var viewportArea: Rect { get }

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

Source · RenderTerminal.swift:10

requiresReanchor

Instance Property
var requiresReanchor: Bool { get }

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

Source · RenderTerminal.swift:11

snapshot

Instance Property
var snapshot: FrameSnapshot? { get }

An on-demand copy of the last successfully presented logical frame.

Nil before the first draw, after resize/invalidation, or after output failure.

Source · RenderTerminal.swift:24

init(backend:width:height:viewport:)

Initializer
init(backend: R, width: Int, height: Int, viewport: Viewport = .fullscreen)

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (4)
backend
Destination that writes terminal bytes or throws.
width
Available columns in terminal cells.
height
Available rows in terminal cells.
viewport
Available terminal-cell viewport.
Source · RenderTerminal.swift:28

localPoint(from:)

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

Converts a physical terminal position to a local frame position, if inside the viewport.

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

Returns Point?.

Source · RenderTerminal.swift:42

physicalPoint(from:)

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

Converts a valid local frame position to a physical terminal position.

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

Returns Point?.

Source · RenderTerminal.swift:48

resize(width:height:)

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

Updates terminal dimensions and invalidates placement/snapshots when required. Frame geometry is recalculated from the viewport.

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

setViewport(_:)

Instance Method
mutating func setViewport(_ viewport: Viewport)

Changes the owned footprint.

The previous footprint is erased on the next draw.

Inline anchors must be confirmed by the caller; this never queries or reads stdin.

Parameters (1)
viewport
Available terminal-cell viewport.
Source · RenderTerminal.swift:69

reanchor(at:)

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

Confirms where inline rendering may resume after resize or uncertain output.

This discards pending insertions and old footprint knowledge. The application must first establish a safe primary-screen cursor position by its own means.

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

invalidate()

Instance Method
mutating func invalidate()

Repaints after external output.

Inline output requires a confirmed new anchor.

Source · RenderTerminal.swift:94

draw(_:)

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

Builds a complete logical frame and presents it through the semantic backend. Only successful presentation advances snapshots.

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

Returns RenderStats.

Source · RenderTerminal.swift:101

insertBefore(_:)

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

Commits full-width styled rows above an inline frame and redraws its current contents.

Uses line feeds on the primary screen, preserving scrollback. Short rows are padded; excess columns are clipped at whole graphemes. Failure may mean partial insertion: subsequent draws and insertions require explicit reanchor(at:).

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

insertBefore(height:render:)

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

Builds styled rows to commit above an inline viewport.

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