Files
asciinema/doc/asciicast-v2.md

207 lines
6.3 KiB
Markdown
Raw Normal View History

2017-03-13 14:08:12 +01:00
# asciicast file format (version 2)
2017-11-19 17:58:36 +01:00
asciicast v2 file is [newline-delimited JSON](http://jsonlines.org/) file where:
2017-03-13 14:08:12 +01:00
* __first line__ contains header (initial terminal size, timestamp and other
meta-data), encoded as JSON object,
2017-11-19 17:58:36 +01:00
* __all following lines__ form an event stream, _each line_ representing a
separate event, encoded as 3-element JSON array.
2017-03-13 14:08:12 +01:00
2017-11-19 17:58:36 +01:00
Example file:
2017-03-15 17:42:37 +01:00
2017-11-19 17:58:36 +01:00
```json
{"version": 2, "width": 80, "height": 24, "timestamp": 1504467315, "title": "Demo", "env": {"TERM": "xterm-256color", "SHELL": "/bin/zsh"}}
[0.248848, "o", "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n"]
[1.001376, "o", "That was ok\rThis is better."]
2023-05-05 10:55:00 +02:00
[1.500000, "m", ""]
2019-03-17 14:33:36 +01:00
[2.143733, "o", "Now... "]
[4.050000, "r", "80x24"]
2017-11-19 17:58:36 +01:00
[6.541828, "o", "Bye!"]
```
2017-03-15 17:42:37 +01:00
Suggested file extension is `.cast`, suggested media type is
`application/x-asciicast`.
## Header
2017-03-13 14:08:12 +01:00
2017-09-17 12:44:48 +02:00
asciicast header is JSON-encoded object containing recording meta-data.
2017-03-14 19:52:23 +01:00
2017-09-17 12:44:48 +02:00
### Required header attributes:
2017-03-14 19:52:23 +01:00
2017-09-17 12:44:48 +02:00
#### `version`
2017-03-14 19:52:23 +01:00
2017-11-19 17:58:36 +01:00
Must be set to `2`. Integer.
2017-09-17 12:44:48 +02:00
#### `width`
Initial terminal width (number of columns). Integer.
#### `height`
Initial terminal height (number of rows). Integer.
### Optional header attributes:
#### `timestamp`
Unix timestamp of the beginning of the recording session. Integer.
#### `duration`
Duration of the whole recording in seconds (when it's known upfront). Float.
#### `idle_time_limit`
Idle time limit, as given via `-i` option to `asciinema rec`. Float.
This should be used by an asciicast player to reduce all terminal inactivity
(delays between frames) to maximum of `idle_time_limit` value.
2017-09-17 12:44:48 +02:00
#### `command`
Command that was recorded, as given via `-c` option to `asciinema rec`. String.
#### `title`
Title of the asciicast, as given via `-t` option to `asciinema rec`. String.
#### `env`
Map of captured environment variables. Object (String -> String).
2017-03-14 19:52:23 +01:00
2017-09-17 12:57:16 +02:00
Example env:
```json
2017-09-17 13:20:17 +02:00
"env": {
"SHELL": "/bin/bash",
"TERM": "xterm-256color"
2017-09-17 13:20:17 +02:00
}
2017-09-17 12:57:16 +02:00
```
2017-11-19 17:58:36 +01:00
> Official asciinema recorder captures only `SHELL` and `TERM` by default. All
> implementations of asciicast-compatible terminal recorder should not capture
> any additional environment variables unless explicitly permitted by the user.
2017-09-17 12:57:16 +02:00
2017-09-17 13:20:17 +02:00
#### `theme`
Color theme of the recorded terminal. Object, with the following attributes:
- `fg` - normal text color,
- `bg` - normal background color,
- `palette` - list of 8 or 16 colors, separated by colon character.
All colors are in the CSS `#rrggbb` format.
Example theme:
```json
"theme": {
"fg": "#d0d0d0",
"bg": "#212121",
"palette": "#151515:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#d0d0d0:#505050:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#f5f5f5"
}
```
2017-11-19 17:58:36 +01:00
> A specific technique of obtaining the colors from a terminal (using xrdb,
> requesting them from a terminal via special escape sequences etc) doesn't
> matter as long as the recorder can save it in the above format.
2017-09-17 13:20:17 +02:00
2017-03-15 17:12:09 +01:00
## Event stream
2017-03-14 19:52:23 +01:00
2017-03-15 17:12:09 +01:00
Each element of the event stream is a 3-tuple encoded as JSON array:
2017-03-14 19:52:23 +01:00
2023-10-18 13:25:36 +02:00
[time, code, data]
2017-03-15 16:00:56 +01:00
Where:
2023-10-18 13:25:36 +02:00
* `time` (float) - indicates when the event happened, represented as the number
of seconds since the beginning of the recording session,
2023-10-18 13:25:36 +02:00
* `code` (string) - specifies type of event, one of: `"o"`, `"i"`, `"m"`, `"r"`
* `data` (any) - event specific data, described separately for each event
code.
2017-03-15 16:00:56 +01:00
For example, let's look at the following line:
2017-03-14 19:52:23 +01:00
2017-09-03 12:41:15 +02:00
[1.001376, "o", "Hello world"]
2017-03-14 19:52:23 +01:00
2023-10-18 13:25:36 +02:00
It represents:
2017-03-15 16:00:56 +01:00
2023-10-18 13:25:36 +02:00
* output (code `o`),
* of text `Hello world`,
* which happened `1.001376` sec after the start of the recording session.
2017-03-15 16:00:56 +01:00
2023-10-18 13:25:36 +02:00
### Supported event codes
2017-03-13 14:08:12 +01:00
2023-10-18 13:25:36 +02:00
This section describes the event codes supported in asciicast v2 format.
2017-03-13 14:08:12 +01:00
2023-10-18 13:25:36 +02:00
The list is open to extension, and new event codes may be added in both the
2017-03-15 17:12:09 +01:00
current and future versions of the format. For example, we may add new event
2023-10-18 13:25:36 +02:00
code for text overlay (subtitles display).
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
A tool which interprets the event stream (web/cli player, post-processor) should
2023-10-18 13:25:36 +02:00
ignore (or pass through) event codes it doesn't understand or doesn't care
about.
2017-03-13 14:08:12 +01:00
2023-10-18 13:25:36 +02:00
#### "o" - output, data written to a terminal
2017-03-13 14:08:12 +01:00
2023-10-18 13:25:36 +02:00
Event of code `"o"` represents printing new data to a terminal.
2017-03-13 14:08:12 +01:00
2023-10-18 13:25:36 +02:00
`data` is a string containing the data that was printed. It must be valid, UTF-8
encoded JSON string as described in [JSON RFC section
2.5](http://www.ietf.org/rfc/rfc4627.txt), with any non-printable Unicode
codepoints encoded as `\uXXXX`.
2017-03-15 17:12:09 +01:00
2023-10-18 13:25:36 +02:00
#### "i" - input, data read from a terminal
2017-03-15 16:00:56 +01:00
2023-10-18 13:25:36 +02:00
Event of code `"i"` represents character typed in by the user, or more
specifically, raw data sent from a terminal emulator to stdin of the recorded
program (usually shell).
2017-03-15 16:00:56 +01:00
2023-10-18 13:25:36 +02:00
`data` is a string containing captured ASCII character representing a key, or a
control character like `"\r"` (enter), `"\u0001"` (ctrl-a), `"\u0003"` (ctrl-c),
etc. Like with `"o"` event, it's UTF-8 encoded JSON string, with any
non-printable Unicode codepoints encoded as `\uXXXX`.
2017-09-22 22:45:41 +02:00
> Official asciinema recorder doesn't capture keyboard input by default. All
2017-11-19 17:58:36 +01:00
> implementations of asciicast-compatible terminal recorder should not capture
2023-10-18 13:25:36 +02:00
> it either unless explicitly requested by the user.
2017-03-15 16:00:56 +01:00
2023-05-05 10:55:00 +02:00
#### "m" - marker
2019-03-17 14:33:36 +01:00
2023-10-18 13:25:36 +02:00
Event of code `"m"` represents a marker.
2019-03-17 14:33:36 +01:00
2023-05-05 10:55:00 +02:00
When marker is encountered in the event stream and "pause on markers"
2019-03-17 14:33:36 +01:00
functionality of the player is enabled, the playback should pause, and wait for
the user to resume.
2023-10-18 13:25:36 +02:00
`data` can be used to annotate a marker. Annotations may be used to e.g.
2023-05-05 10:55:00 +02:00
show a list of named "chapters".
2019-03-17 14:33:36 +01:00
#### "r" - resize
2023-10-18 13:25:36 +02:00
Event of code `"r"` represents terminal resize.
2023-10-18 13:25:36 +02:00
Those are captured in response to `SIGWINCH` signal.
`data` contains new terminal size (columns + rows) formatted as
`"{COLS}x{ROWS}"`, e.g. `"80x24"`.
2017-11-19 17:58:36 +01:00
## Notes on compatibility
2017-03-15 16:00:56 +01:00
2017-11-19 17:58:36 +01:00
Version 2 of asciicast file format solves several problems which couldn't be
easily fixed in the old format:
2017-03-15 17:12:09 +01:00
2017-11-19 17:58:36 +01:00
* minimal memory usage when recording and replaying arbitrarily long sessions -
disk space is the only limit,
* when the recording session is interrupted (computer crash, accidental close of
terminal window) you don't lose the whole recording,
* it's real-time streaming friendly.
2017-03-13 14:08:12 +01:00
2017-11-19 17:58:36 +01:00
Due to file structure change (standard JSON => newline-delimited JSON) version 2
is not backwards compatible with version 1. Support for v2 has been added in:
2017-03-13 14:08:12 +01:00
* [asciinema terminal recorder](https://github.com/asciinema/asciinema) - 2.0.0
2017-11-19 17:58:36 +01:00
* [asciinema web player](https://github.com/asciinema/asciinema-player) - 2.6.0
* [asciinema server](https://github.com/asciinema/asciinema-server) - v20171105
tag in git repository