Skip to content
github-actions[bot] edited this page Sep 23, 2026 · 5 revisions

Motion

glyphora separates content from presentation in time. Widgets first render a normal, deterministic frame; active Effects then transform its cells using elapsed time. That keeps motion out of widget state and makes effects composable and replayable.

Use motion to explain change, preserve context, or add a brief sense of arrival—not to delay every interaction.

Animation ticks

Motion needs the runtime to produce frames while time passes, and an animated widget asks for those frames itself. This app animates with no configuration at all:

def view(using ReactiveScope, Theme): Element = spinner("deploying")

Reading the ambient AnimationClock — which every animated widget does — records how often that widget needs a frame. After each render the app turns one repeating tick on at the shortest interval anything on the frame asked for, and off again when a frame asks for nothing. So an app showing a spinner ticks, an app showing a static screen does not, and neither one had to say so.

Ticks delivered this way arrive at the input loop's own cadence, which is about ten a second when no tick rate is configured. That is the difference between "the spinner spins" and "the spinner is perfectly smooth". For motion you want to look deliberate, set the rate explicitly:

import scala.concurrent.duration.*

override def config = RunnerConfig(tickRate = Some(50.millis))

Twenty frames per second is usually enough for terminal animation. Faster ticks increase CPU and terminal traffic without guaranteeing a smoother emulator. A configured tickRate also drives onTick, which the negotiated ticks deliberately do not — an app that never asked for ticks does not start receiving that callback.

Either way there is no counter to declare, advance, or thread through a view — see the animation clock below.

Three kinds of motion

They are not interchangeable, and reaching for the wrong one is the usual source of motion that feels wrong:

Kind Use Driven by
Animated widgets — spinner, progressBar, orbitSpinner, animatedText, … ongoing status: something is working, something is loading the ambient AnimationClock
Frame effects — Effect.fadeIn, sweepIn, … a transition: arriving, leaving, drawing attention once runEffect, elapsed since it started
Tween / Spring a value your view consumes — a ratio, an offset, a scroll position elapsed time you supply

An Effect transforms the cells of a finished frame. An animated widget draws different cells. A Tween changes a number your widgets are built from. Use an effect for a transition, a widget for a state, and a tween for a value.

The animation clock

Every animated widget reads elapsed time from the ambient AnimationClock, so this is a complete animated app:

override def config = RunnerConfig(tickRate = Some(50.millis))

def view(using ReactiveScope, Theme): Element = spinner("deploying")

The read is tracked, which is what makes this more than a shorthand: a view only subscribes to the clock when it actually renders an animation, so a screen with no animation on it is not repainted by the ticks. Hand-rolling a Signal[Int] counter and reading it in view repaints the whole app on every tick forever, whether anything is moving or not.

Speeds are wall-clock, not tick counts. A preset that holds each frame for 80 ms looks the same in an app ticking every 50 ms and one ticking every 200 ms; expressing speed in ticks would make the same animation read as sluggish in one and frantic in the other.

Every animated widget is a pure function of elapsed time, so each has a …At(elapsed) twin — spinnerAt, orbitSpinnerAt, animatedTextAt, indeterminateBarAt, skeletonAt, marqueeAt, linearSpinnerAt, spinnerGridAt — for driving from a clock of your own. See Widgets for the catalogue.

Run a frame effect

From a key, mouse, or other render-thread handler:

runEffect(Effect.sweepIn(350.millis, Easing.CubicOut))

The effect applies to the full frame after normal rendering. When a finite effect finishes, the runtime removes it and paints one final unmodified frame.

Pick an effect

Effect Visual behavior Good for
fadeIn / fadeOut interpolates foreground colors from/to black gentle screen transitions
coalesce / dissolve reveals/hides cells in deterministic random order splash and success moments
sweepIn reveals columns left to right page or panel arrival
slideInFromRight shifts content in from the right directional navigation
typewriter reveals cells in row-major reading order short messages and intros
pulse endless brightness oscillation a single live/attention state

Most finite effects take a duration and optional Easing. Scatter effects also take a seed; equal seeds produce equal cell order, which makes testing repeatable.

Effect.coalesce(
  duration = 600.millis,
  easing = Easing.QuadOut,
  seed = 42,
)

Compose timelines

val reveal = Effect.sequence(
  Effect.coalesce(450.millis),
  Effect.delay(150.millis, Effect.fadeIn(250.millis)),
)

val energetic = Effect.parallel(
  Effect.sweepIn(350.millis, Easing.CubicOut),
  Effect.fadeIn(240.millis),
)

val threePulses = Effect.repeat(Effect.fadeIn(180.millis), times = 3)
  • sequence runs effects one after another;
  • parallel runs all effects and completes with the longest;
  • delay holds an effect at zero progress before it begins;
  • repeat loops a finite effect a fixed number of times.

An infinite effect such as pulse never prunes itself. Use it sparingly, and avoid placing one inside a sequence that needs to continue.

Choose an easing curve

Easing.Linear moves at constant speed. The Quad, Cubic, Quart, Quint, Sine, Expo, and Circ families provide In, Out, and InOut variants. Back, Elastic, and Bounce intentionally overshoot or oscillate.

A practical default set:

  • QuadOut — quick start, gentle finish; most entrances;
  • QuadIn — accelerates away; exits;
  • CubicInOut — symmetric state transition;
  • Linear — progress tied directly to time;
  • BackOut — playful overshoot for a small, isolated value.

Animate a value with Tween

Tween is for numbers that your view consumes—gauge ratios, offsets, or a chart range—rather than whole-frame cell transforms:

import scala.concurrent.duration.*

private val progress = Tween(0.0, 1.0, 800.millis, Easing.CubicOut)

def view(using ReactiveScope, Theme): Element =
  gauge(progress.at(AnimationClock.elapsed))

The clock is shared with the animated widgets, so a tween and a spinner in the same view stay in step, and reading it here subscribes this view to the ticks for exactly as long as it renders the tween. Supply your own elapsed value instead when the animation is tied to something other than wall time — progress through a download, say, rather than seconds.

Tween.at clamps through the easing function, so values remain at their completed endpoint after the duration.

Use a spring for physical motion

A Spring has no fixed duration. Step it each tick until it settles:

private val spring = Spring(frequency = 6.0, damping = 0.75, deltaTime = 0.05)
private var position = 0.0
private var velocity = 0.0
private val target = Signal(100.0)

override def onTick(): Unit =
  val next = spring.step(Spring.State(position, velocity), target.peek)
  position = next.position
  velocity = next.velocity

Lower damping bounces; 1.0 is approximately critically damped; higher values feel slower. Springs suit scroll or selection motion where a destination can change mid-flight.

Build a skippable splash

override def splash = Some(
  SplashScreen(
    content = centered(40, 7) {
      column(
        bigText("GLYPHORA").fg(Color.Cyan),
        text("terminal UI, written like Scala").dim,
      )
    },
    effect = Effect.coalesce(650.millis),
    minimumDuration = 1.second,
  )
)

The splash runs before the first normal view. Any key skips it, and glyphora supplies a default tick when the app config has none.

Motion checklist

  • Keep most transitions under 500 ms.
  • Never animate away an error or required action.
  • Prefer one dominant effect over several competing ones.
  • Offer a reduced-motion setting for persistent animation. The quietest built-ins are IndeterminateMotion.Pulse (brightens in place, no travel), spinnerGrid().uniform (every slot in lockstep), and SpinnerPreset.Ellipsis.
  • Test finite effects at zero, halfway, completion, and after completion.
  • Use stable scatter seeds in tests.

Effects process the same buffers used by headless tests, and AnimationClock.freezeAt pins the clock so an animated widget renders a known frame; see Testing for both.

Clone this wiki locally