Files
asciinema/doc/asciicast-v2.md

102 lines
3.5 KiB
Markdown
Raw Normal View History

2017-03-13 14:08:12 +01:00
# asciicast file format (version 2)
2017-03-14 19:52:23 +01:00
asciicast v2 file
is [NDJSON (newline delimited JSON)](https://github.com/ndjson/ndjson-spec) file
where:
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
* __first line__ contains meta-data (duration, initial terminal size, etc),
encoded as JSON object,
* __all subsequent lines__ form an event stream, _each line_ representing a
2017-03-15 17:13:40 +01:00
separate event stream item, encoded as JSON array.
2017-03-13 14:08:12 +01:00
2017-03-14 19:52:23 +01:00
## Meta-data
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
The following meta-data is **required** in asciicast v2:
2017-03-14 19:52:23 +01:00
* `version` - set to 2,
2017-03-15 17:12:09 +01:00
* `width` - initial terminal width (number of columns),
* `height` - initial terminal height (number of rows).
The following meta-data is **optional** in asciicast v2:
* `command` - command that was recorded, as given via `-c` option to `asciinema rec`,
* `title` - title of the asciicast, as given via `-t` option to `asciinema rec`,
2017-03-14 19:52:23 +01:00
* `env` - map of environment variables useful for debugging playback problems.
Example meta-data line:
2017-03-15 17:12:09 +01:00
{ "version": 2, "width": 80, "height": 24, "command": "/bin/zsh", "title": null, "env": { "TERM": "xterm-256color", "SHELL": "/bin/zsh" } }
2017-03-14 19:52:23 +01: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
[ time, event-type, event-data ]
2017-03-15 16:00:56 +01:00
Where:
2017-03-15 17:12:09 +01:00
* `time` (number) - relative time (in seconds) since the previous event occured
(or since the beginning of the recording session for the first event in the
stream),
* `event-type` (string) - one of: `"o"`, `"i"`, `"size"`,
2017-03-15 16:00:56 +01:00
* `event-data` (any) - event specific data, described separately for each event
2017-03-15 17:12:09 +01:00
type.
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
[ 1.001376, "o", "Hello world" ]
2017-03-15 17:12:09 +01:00
It represents the event which:
2017-03-15 16:00:56 +01:00
2017-03-15 17:12:09 +01:00
* happened 1.001376 sec after a previous event in the stream,
* is of type `"o"` (print to stdout, see below),
* has data `"Hello world"`.
2017-03-15 16:00:56 +01:00
2017-03-15 17:12:09 +01:00
### Supported event types
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
This section describes the event types supported in asciicast v2 format.
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
The list is open to extension, and new event types may be added in both the
current and future versions of the format. For example, we may add new event
type 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
ignore event types it doesn't understand or doesn't care about. However, it
should honor the amount of time specified by such stream item (by pausing for
this amount of time when playing back) in order to keep the subsequent events on
the timeline.
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
#### "o" - output, printing to stdout
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
Event of type `"o"` represents printing new data to terminal's stdout.
2017-03-13 14:08:12 +01:00
2017-03-15 17:12:09 +01:00
`event-data` is a string containing the data that was printed to a terminal. It
has to be valid, UTF-8 encoded JSON string as described
in [JSON RFC section 2.5](http://www.ietf.org/rfc/rfc4627.txt), with all
non-printable Unicode codepoints encoded as `\uXXXX`.
#### "i" - input, from keyboard (planned?)
2017-03-15 16:00:56 +01:00
TODO
2017-03-15 17:12:09 +01:00
not supported by current versions of the recorder and players
#### "size" - terminal resize (planned?)
2017-03-15 16:00:56 +01:00
TODO
2017-03-15 17:12:09 +01:00
not supported by current versions of the recorder and players
2017-03-14 19:52:23 +01:00
## Complete asciicast v2 example
2017-03-13 14:08:12 +01:00
2017-03-14 19:52:23 +01:00
A very short asciicast v2 file looks like this:
2017-03-13 14:08:12 +01:00
2017-03-14 19:52:23 +01:00
{ "version": 2, "width": 80, "height": 24, "duration": 1.515658, "command": "/bin/zsh", "title": null, "env": { "TERM": "xterm-256color", "SHELL": "/bin/zsh" } }
2017-03-13 14:08:12 +01:00
[ 0.248848, "o", "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n" ]
2017-03-14 19:52:23 +01:00
[ 1.001376, "o", "This is overwritten\rThis is better." ]
[ 0.143733, "o", " " ]
[ 0.541828, "o", "Bye!" ]
2017-03-15 17:12:09 +01:00
The final `"Bye!"` was printed to a terminal after 1.935785 sec (0.248848 +
1.001376 + 0.143733 + 0.541828).