Asciinema
asciinema plays a .cast terminal recording in the page. Use it when a
command-line procedure is easier to follow when watched: an installation, a
migration, a long-running build. Unlike a video, the terminal output stays
text, so readers can pause and copy a command out of the player, and the
three-minute installation on this page weighs about 196 KB. For graphical
interfaces, use screenshots or a video instead. The
player and its styles ship with the theme, so nothing is downloaded at build
time and no CDN is contacted.
Shortest form
file is the only required parameter:
This is a single-node Pigsty installation on Debian, recorded in a 120×36
terminal: 6 min 42 s of real time, which its 0.5 s idle limit plays back in
about 3 minutes. To try it on your own site,
download the sample recording to
static/images/install.cast. file is a path from the site root, and the
same value also finds a file under assets/, because the theme looks for a
global resource first. Page-bundle files are not found. Without title, the
window title shows the value of file.
Window title and theme
title names the window and theme sets the terminal colors:
The default, theme="auto", follows the site: td-light in light mode and
td-dark in dark mode, and the player redraws in place when the reader
switches. Any other value fixes the palette in both modes: the player’s own
asciinema, dracula, gruvbox-dark, monokai, nord, seti,
solarized-dark, solarized-light and tango, or the theme’s td-light and
td-dark. A fixed light palette such as solarized-light looks out of place
on a dark page, so prefer auto unless the recording needs its own colors. The
terminal font is always the site’s code font.
Speed, start point and poster
For a long recording, speed sets the playback rate, startAt skips the
opening, and poster chooses the frame shown before the reader presses play:
speed and startAt are numbers, startAt in seconds. poster uses the
player’s npt: time notation, so npt:1:30 is the frame at one minute thirty:
the player above shows that frame and starts playing from second 60.
idleTimeLimit shortens every silent stretch to at most that many seconds.
This recording needs none, because its .cast header already sets
idle_time_limit: 0.5; use it for a recording made without an idle limit.
Chapter markers
markers puts named chapters on the progress bar, so a reader can jump to the
part of a long recording they came for. Write each chapter as time:label,
with the time in seconds, and separate chapters with commas:
Hover a mark to read its label; with the player focused, [ and ] jump to
the previous and next chapter. The marks appear once the recording has
loaded, so pair markers with preload="true" when they should show before
the reader presses play. pauseOnMarkers="true" stops at every chapter, which
suits a walkthrough the reader steps through.
Times count on the player’s clock, after the idle limit (idleTimeLimit, or
the one in the .cast header) has shortened the silences, so take them from
the player’s timer rather than from the .cast file. A label may contain
colons but not commas, and a chapter written as a bare time has no label.
Size and fit
The player takes its terminal size from the .cast header and scales to the
width of the column (fit="width"). cols and rows override the header:
A size smaller than the recording clips it: the player above shows 16 of the
36 rows. Use cols and rows to correct a header that has the wrong size, not
to make the player smaller; for a shorter player, record again in a smaller
terminal.
fit decides how the terminal scales: width (the default) fits the column
width, height fits the container’s height, both fits both, and none keeps
the font at its natural size, so a wide terminal overflows the column.
Looping and preloading
loop starts again at the end. preload fetches the recording as soon as the
player appears, so it starts without a pause when the reader presses play:
autoplay="true" starts playback without a click. Avoid it: the reader’s
“reduce motion” setting only turns off the player’s control animations, not
autoplay, so a moving terminal is forced on everyone. If you must autoplay,
keep the clip very short, add loop, and use one per page.
Inside steps
A recording works best beside the step it shows: the text says what to do, the recording shows what happens.
-
Install the dependencies and fetch the installer:
-
Run the install; the recording plays the process at four times speed:
pig install -
Open
http://<node address>:3000and sign in to Grafana withadmin / pigsty.
A page can hold any number of players; the script and styles load once.
Recording a cast file
Record with asciinema, for example
asciinema rec --idle-time-limit=2 --cols=100 --rows=28 install.cast, and
check the result with asciinema play install.cast before you commit it.
- Keep the terminal under 100 columns so the text stays legible on a phone,
and run
clearbefore you start. - Remove secrets before you record. A
.castfile is plain text, so every character typed or printed can be found withgrep; read the file before committing it. - Commit the file to your site, for example as
static/images/install.castwithfile="images/install.cast", rather than pointing at another site’s.cast. A remote recording breaks when that site moves it.
Output
Print, RSS and the page’s Markdown output have no player: each shows the
recording as a link with its title. Readers of a printed page, feed readers
and tools that read llms.txt therefore get only that link and your prose, so
write the key commands and their output beside the recording as text or code.
Parameter reference
file, ,- Named, or the first positional parameter. Looked up as a global resource in
assets/, then as a path from the site root; anhttporhttpsURL is used as is theme, ,autofollows the site’s color scheme; ortd-lighttd-darkasciinemadraculagruvbox-darkmonokainordsetisolarized-darksolarized-lighttangomarkers, ,- Named chapters on the progress bar, times in seconds on the player’s clock; see Chapter markers
The on/off parameters are on only when their value is the text true, so
loop="true" and loop=true both work and anything else means off. Other
invalid values warn and fall back: an unknown fit uses width, a speed
that is not a positive number uses 1, a non-numeric startAt uses 0, and
non-numeric cols, rows, idleTimeLimit or marker times are ignored. A
file with another scheme, a protocol-relative //host address, or an empty
value warns and renders nothing.
Limits
- The player needs JavaScript. With scripts off, the window frame holds a link to the recording instead.
- Site search indexes page text, not recordings, so a command that appears only in a recording cannot be found.
- Few readers finish a recording longer than five or six minutes. Split a long procedure into short recordings, each with its own text.
Related
- Code blocks — the key commands and output, copyable
- Steps — the recording beside the step it belongs to
- Images — static screenshots: recordings for terminals, screenshots for graphical interfaces
- Include — when the same commands appear on several pages