loom & weft
Made for Swift.

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

LOOM Unreleased (PR #2) / ANIMATION

SymbolAnimation

No timer is started. Sample from your own elapsed clock and schedule another draw using nextFrame. Empty frame lists become one blank frame. Nonpositive/non-finite frame durations become 0.133 seconds; negative/non-finite elapsed times use the first frame. A one-frame animation is static.

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

let animation = SymbolAnimation.spinner(style: Style(foreground: .rgb(237, 166, 98)))
let sample = animation.sample(at: 1.25)
_ = (sample.symbol, animation.nextFrame(after: 1.25))
Members on this page

Feature guides and release status

SymbolAnimation

Structure
struct SymbolAnimation

Conforms to: Swift.Sendable, Swift.SendableMetatype.

A deterministic sequence of terminal symbols and styles, driven by the caller's clock.

This value owns no timer. Schedule only while visible, and render at frame boundaries.

Source · SymbolAnimation.swift:6

Sample

Structure
struct Sample

Conforms to: Swift.Equatable, Swift.Sendable, Swift.SendableMetatype.

One animation frame’s symbol and style. Construct samples for a custom SymbolAnimation.

Source · SymbolAnimation.swift:7

Sample.symbol

Instance Property
let symbol: String

The visible grapheme or symbol string.

Source · SymbolAnimation.swift:8

Sample.style

Instance Property
let style: Style

Visual attributes used when painting this value.

Source · SymbolAnimation.swift:9

Sample.init(_:style:)

Initializer
init(_ symbol: String, style: Style = Style())

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

Parameters (2)
symbol
Argument type and any default are shown in the declaration; see the behavior notes above.
style
Text/cell appearance.
Source · SymbolAnimation.swift:11

frames

Instance Property
let frames: [Sample]

Samples used by the looping animation.

Source · SymbolAnimation.swift:17

frameDuration

Instance Property
let frameDuration: TimeInterval

Seconds per sample after initializer validation.

Source · SymbolAnimation.swift:18

init(frames:frameDuration:)

Initializer
init(frames: [Sample], frameDuration: TimeInterval)

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

Parameters (2)
frames
Animation samples in loop order.
frameDuration
Seconds per animation sample.
Source · SymbolAnimation.swift:20

sample(at:)

Instance Method
func sample(at elapsed: TimeInterval) -> Sample

Returns the current sample, wrapping over frames by elapsed time. Negative/non-finite elapsed time uses frame zero.

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

Returns SymbolAnimation.Sample.

Source · SymbolAnimation.swift:25

nextFrame(after:)

Instance Method
func nextFrame(after elapsed: TimeInterval) -> TimeInterval?

Seconds until the next frame boundary; nil for a static sequence.

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

Returns TimeInterval?.

Source · SymbolAnimation.swift:30

spinner(style:)

Type Method
static func spinner(style: Style = Style()) -> SymbolAnimation

Braille activity indicator, approximately 7.5 frames per second.

Parameters (1)
style
Text/cell appearance.

Returns SymbolAnimation.

Source · SymbolAnimation.swift:43

activity(style:)

Type Method
static func activity(style: Style = Style()) -> SymbolAnimation

Slower background activity cycle, approximately one loop per second.

Parameters (1)
style
Text/cell appearance.

Returns SymbolAnimation.

Source · SymbolAnimation.swift:48

pulse(symbol:low:high:style:)

Type Method
static func pulse(symbol: String = "◆", low: UInt8 = 80, high: UInt8 = 160, style: Style = Style()) -> SymbolAnimation

Smooth foreground brightness pulse; never changes the terminal background.

Parameters (4)
symbol
Argument type and any default are shown in the declaration; see the behavior notes above.
low
Argument type and any default are shown in the declaration; see the behavior notes above.
high
Argument type and any default are shown in the declaration; see the behavior notes above.
style
Text/cell appearance.

Returns SymbolAnimation.

Source · SymbolAnimation.swift:53