asciinema is a terminal session recording and playback tool. With the :::asciinema directive, you can embed recorded terminal sessions directly in your blog posts.
Basic Example
Here’s a simple terminal session demo:
Usage
Use the :::asciinema directive in Markdown files:
:::asciinema{src="/casts/demo.cast"}markdownRecording .cast Files
Use the asciinema CLI to record terminal sessions:
# Install
brew install asciinema # macOS
sudo apt install asciinema # Ubuntu
# Record
asciinema rec demo.cast
# Record a specific command
asciinema rec -c "pnpm run build" build-demo.cast
# Set idle time compression
asciinema rec -i 2 demo.castbashPress Ctrl+D or type exit to stop recording. Place the generated .cast file in public/casts/ to reference it.
Auto Play
Set autoPlay to start playback automatically:
Directive Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
src | string | required | Path to .cast file |
cols | string | 80 | Terminal columns |
rows | string | 24 | Terminal rows |
speed | string | 1 | Playback speed multiplier |
idleTimeLimit | string | 2 | Idle time compression threshold (seconds) |
fit | string | "width" | Fit mode |
autoPlay | string | false | Auto-start playback |
loop | string | false | Loop playback |
The player automatically follows the blog’s light/dark theme.
评论区
文明评论,共建和谐社区