Recordings
tui-test records live terminal sessions into animated raster media (.gif, .apng/.png, .mp4) or timestamped asciinema streams (.cast). For scripted demos written in a declarative VHS-like syntax, see tape files.
Formats and requirements
Section titled “Formats and requirements”| Extension | Format | Requirements |
|---|---|---|
.gif |
Animated GIF | Built in on CLI, JS, Python, and Go; recording-raster + fonts in Rust. |
.png, .apng |
Animated PNG | Built in on CLI, JS, Python, and Go; recording-raster + fonts in Rust. |
.mp4 |
H.264 MP4 video | Same raster support plus ffmpeg on PATH (no transparent background). |
.cast |
Asciicast v2 (cast) or v3 (cast3) |
No font or raster dependencies; use a player that supports the selected version. |
The output path extension chooses the format unless overridden by format (--format).
Asciicast versions
Section titled “Asciicast versions”The .cast extension selects v2. Select cast3 explicitly for v3; both versions use the same extension.
| API | Explicit v3 recording |
|---|---|
| CLI | tui-test record start demo.cast --format cast3 |
| JavaScript | await terminal.startRecording("demo.cast", { format: "cast3" }) |
| Python | await terminal.start_recording("demo.cast", format="cast3") |
| Rust | Operation::StartRecording { format: Some(RecordingFormat::Cast3), ... } |
| Go | terminal.StartRecording("demo.cast", tuitest.RecordingOptions{Format: tuitest.Cast3}) |
Use cast (RecordingFormat::Cast in Rust, tuitest.Cast in Go) for v2.
V3 stores terminal metadata under term and records intervals between events.
V2 retains its existing header and elapsed timestamps.
Both formats record the child’s launch-time TERM, including environment overrides.
Neither format supports raster canvas options or pause/resume.
The portable example
checks explicit and automatic recordings with TERM=vt100:
cargo run -p tui-test-rs --example asciicast_versionsStart, pause, resume, and stop
Section titled “Start, pause, resume, and stop”Raster recordings sample the live terminal at fps (default 30) and preserve real elapsed time until stopRecording finishes writing the file. Use pauseRecording and resumeRecording to skip slow setup steps in .gif, .apng, or .mp4 captures while the child process keeps running; asciinema .cast streams reject pause and resume.
const terminal = TuiTest.ephemeral("demo", { style: { fontSize: 20, window: { titleBar: false }, cursor: { blink: true, blinkIntervalMs: 400 }, },});try { await terminal.run("my-app"); await terminal.getByText("Ready").expect(); await terminal.startRecording("demo.gif", { fps: 30, idleTimeLimit: 1.5, speed: 1.25, }); await terminal.getByText("Deploy").click(); await terminal.pauseRecording(); await terminal.getByText("Provisioning complete").expect(); await terminal.resumeRecording(); await terminal.getByText("Healthy").expect(); await terminal.stopRecording();} finally { await terminal.closeQuiet();}from tui_test import RecordingCursorStyle, RenderStyle, TuiTest, WindowStyle
style = RenderStyle( font_size=20, window=WindowStyle(title_bar=False), cursor=RecordingCursorStyle(blink=True, blink_interval_ms=400),)async with TuiTest.ephemeral("demo", style=style) as terminal: await terminal.run("my-app") await terminal.get_by_text("Ready").expect() await terminal.start_recording( "demo.gif", fps=30, idle_time_limit=1.5, speed=1.25, ) await terminal.get_by_text("Deploy").click() await terminal.pause_recording() await terminal.get_by_text("Provisioning complete").expect() await terminal.resume_recording() await terminal.get_by_text("Healthy").expect() await terminal.stop_recording()use tui_test::{Backend, Operation, RunOptions, Session};
let terminal = Session::new("demo");let mut style = tui_test::render::style::Style::default();style.font_size = 20.0;style.window.title_bar = false;terminal.run(RunOptions { program: "my-app".into(), args: vec![], backend: Backend::Alacritty, profile: Default::default(), cols: 80, rows: 30, cwd: None, env: vec![], wait_ready: None, restart: false, timeouts: Default::default(), recording: Default::default(), style,})?;terminal.get_by_text("Ready").expect()?;terminal.execute(Operation::StartRecording { path: "demo.gif".into(), format: None, fps: Some(30), speed: Some(1.25), idle_time_limit: Some(1.5), zoom: None, background: None,})?;terminal.get_by_text("Deploy").click()?;terminal.execute(Operation::PauseRecording)?;terminal.get_by_text("Provisioning complete").expect()?;terminal.execute(Operation::ResumeRecording)?;terminal.get_by_text("Healthy").expect()?;terminal.execute(Operation::StopRecording)?;terminal.close()?;style := &tuitest.RenderStyle{ FontSize: tuitest.Ptr(20.0), Window: tuitest.WindowStyle{TitleBar: tuitest.Ptr(false)},}terminal, err := tuitest.Ephemeral("demo", tuitest.ClientOptions{Style: style})if err != nil { t.Fatal(err)}defer terminal.CloseQuiet()
if _, err := terminal.Run("my-app", nil, tuitest.SpawnOptions{}); err != nil { t.Fatal(err)}if err := terminal.GetByText("Ready", tuitest.TextSelectorOptions{}).Expect(tuitest.LocatorExpectOptions{}); err != nil { t.Fatal(err)}err = terminal.StartRecording("demo.gif", tuitest.RecordingOptions{ FPS: tuitest.Ptr(uint32(30)), IdleTimeLimit: tuitest.Ptr(1.5), Speed: tuitest.Ptr(1.25),})if err != nil { t.Fatal(err)}if err := terminal.GetByText("Deploy", tuitest.TextSelectorOptions{}).Click(tuitest.LocatorClickOptions{}); err != nil { t.Fatal(err)}if err := terminal.PauseRecording(); err != nil { t.Fatal(err)}if err := terminal.GetByText("Provisioning complete", tuitest.TextSelectorOptions{}).Expect(tuitest.LocatorExpectOptions{}); err != nil { t.Fatal(err)}if err := terminal.ResumeRecording(); err != nil { t.Fatal(err)}if err := terminal.GetByText("Healthy", tuitest.TextSelectorOptions{}).Expect(tuitest.LocatorExpectOptions{}); err != nil { t.Fatal(err)}if _, err := terminal.StopRecording(); err != nil { t.Fatal(err)}tui-test --session demo run my-apptui-test --session demo expect text "Ready"tui-test --session demo record start demo.gif --fps 30 --idle-time-limit 1.5 --speed 1.25tui-test --session demo click text "Deploy"tui-test --session demo record pausetui-test --session demo expect text "Provisioning complete"tui-test --session demo record resumetui-test --session demo expect text "Healthy"tui-test --session demo record stoptui-test --session demo closeTiming, cursor blink, and automatic casts
Section titled “Timing, cursor blink, and automatic casts”idleTimeLimit (--idle-time-limit SECONDS) caps unchanged intervals before speed (--speed) scales frame durations. By default there is no idle cap and no extra hold after stop.
Cursor animation requires both style.cursor.blink = true (default) and an application cursor shape that requests blinking. Each visible or hidden phase lasts blinkIntervalMs (default 500 ms) before speed scaling.
To keep an automatic asciinema cast without trace artifacts, pass --recording-mode on-failure or --recording-mode always to tui-test open or tui-test run. In a library, set recording.mode. Use [trace] instead if you also want trace artifacts.
Retrieve an active or retained cast with tui-test get-recording, getRecording(session), get_recording(session), Recording(session), or session.recording(). Automatic casts remain continuous even while an explicit raster recording is paused. Recorded files can contain terminal text, environment output, and window titles; review captures before publishing or attaching them to public issues.
Recording is disabled by default. Selecting a format does not enable capture.
Set [recording] format = "cast3" for v3 automatic recordings. This example keeps a v3 cast and trace artifacts on failure:
[recording]format = "cast3"
[trace]mode = "on-failure"directory = "traces"Language APIs accept the same choice through JavaScript recording: { format: "cast3" },
Python AutomaticRecording(format="cast3"), Rust AutomaticRecording { format: Some(RecordingFormat::Cast3), ..Default::default() },
or Go AutomaticRecording{Format: tuitest.Cast3}.
Constructor and spawn options can select the automatic format.
Omitting the format preserves v2.