|
| 1 | +# asciicast v3 |
| 2 | + |
| 3 | +!!! warning |
| 4 | + |
| 5 | + While this new file format is mostly fleshed out, there still may be small |
| 6 | + changes made to it before the final release of the asciinema CLI 3.0. |
| 7 | + |
| 8 | +asciicast v3 is a file format for terminal sessions recorded by [asciinema |
| 9 | +CLI](../cli/index.md) 3.0 and later. |
| 10 | + |
| 11 | +It's based on [newline-delimited JSON](http://jsonlines.org/). |
| 12 | + |
| 13 | +First line, encoded as JSON object, represents [the header](#header), which |
| 14 | +contains metadata, such as initial terminal size, timestamp, etc. |
| 15 | + |
| 16 | +All following lines form [the event stream](#event-stream). _Each line_ |
| 17 | +represents a separate event, encoded as 3-element JSON array. |
| 18 | + |
| 19 | +Lines starting with `#` character are treated as comments and ignored for most |
| 20 | +intends and purposes. The first line of the file must not be a comment. |
| 21 | + |
| 22 | +asciicast v3 file looks like this: |
| 23 | + |
| 24 | +``` json |
| 25 | +{"version": 3, "term": {"cols": 80, "rows": 24, "type": "xterm-256color"}, "timestamp": 1504467315, "title": "Demo", "env": {"TERM": "xterm-256color", "SHELL": "/bin/zsh"}} |
| 26 | +# event stream follows the header |
| 27 | +[0.248848, "o", "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n"] |
| 28 | +[1.001376, "o", "That was ok\rThis is better."] |
| 29 | +[3.500000, "m", ""] |
| 30 | +[0.143733, "o", "Now... "] |
| 31 | +# terminal window resized to 90 cols and 30 rows |
| 32 | +[2.050000, "r", "90x30"] |
| 33 | +[1.541828, "o", "Bye!"] |
| 34 | +``` |
| 35 | + |
| 36 | +## Header |
| 37 | + |
| 38 | +asciicast header is JSON-encoded object containing recording metadata. |
| 39 | + |
| 40 | +Complete header example, pretty formatted for readability: |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "version": 3, |
| 45 | + "term": { |
| 46 | + "cols": 80, |
| 47 | + "rows": 24, |
| 48 | + "type": "xterm-256color", |
| 49 | + "version": "VTE(7802)", |
| 50 | + "theme": { |
| 51 | + "fg": "#d0d0d0", |
| 52 | + "bg": "#212121", |
| 53 | + "palette": "#151515:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#d0d0d0:#505050:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#f5f5f5" |
| 54 | + } |
| 55 | + }, |
| 56 | + "timestamp": 1509091818, |
| 57 | + "idle_time_limit": 2, |
| 58 | + "command": "/bin/bash", |
| 59 | + "title": "Demo", |
| 60 | + "env": { |
| 61 | + "SHELL": "/bin/bash" |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +Minimal header example: |
| 67 | + |
| 68 | +```json |
| 69 | +{"version": 3, "term": {"cols": 80, "rows": 24}} |
| 70 | +``` |
| 71 | + |
| 72 | +Below list contains all attributes supported in the header. Attributes not |
| 73 | +marked as required may be omitted from the header, as seen in the minimal |
| 74 | +example above. |
| 75 | + |
| 76 | +### `version` |
| 77 | + |
| 78 | +Format version number. |
| 79 | + |
| 80 | +Must be set to `3`. |
| 81 | + |
| 82 | +__Required__ field. |
| 83 | + |
| 84 | +Type: integer |
| 85 | + |
| 86 | + |
| 87 | +### `term` |
| 88 | + |
| 89 | +Terminal information. |
| 90 | + |
| 91 | +__Required__ field. |
| 92 | + |
| 93 | +Type: object with the following attributes: |
| 94 | + |
| 95 | +#### `cols` |
| 96 | + |
| 97 | +Terminal width, i.e. number of columns. |
| 98 | + |
| 99 | +__Required__ field. |
| 100 | + |
| 101 | +Type: integer |
| 102 | + |
| 103 | +#### `rows` |
| 104 | + |
| 105 | +Terminal height, i.e. number of rows. |
| 106 | + |
| 107 | +__Required__ field. |
| 108 | + |
| 109 | +Type: integer |
| 110 | + |
| 111 | +#### `type` |
| 112 | + |
| 113 | +Terminal type, e.g. xterm-256color. |
| 114 | + |
| 115 | +Type: string |
| 116 | + |
| 117 | +#### `version` |
| 118 | + |
| 119 | +Terminal version as reported by XTVERSION OSC query. |
| 120 | + |
| 121 | +Type: string |
| 122 | + |
| 123 | +#### `theme` |
| 124 | + |
| 125 | +Color theme of the recorded terminal. |
| 126 | + |
| 127 | +Type: object, with the following attributes (all required): |
| 128 | + |
| 129 | +- `fg` - normal text color, |
| 130 | +- `bg` - normal background color, |
| 131 | +- `palette` - list of 8 or 16 colors, separated by colon character. |
| 132 | + |
| 133 | +All colors are in the CSS `#rrggbb` format. |
| 134 | + |
| 135 | +Example theme, pretty formatted for readability: |
| 136 | + |
| 137 | +```json |
| 138 | +{ |
| 139 | + "fg": "#d0d0d0", |
| 140 | + "bg": "#212121", |
| 141 | + "palette": "#151515:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#d0d0d0:#505050:#ac4142:#7e8e50:#e5b567:#6c99bb:#9f4e85:#7dd6cf:#f5f5f5" |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +!!! note |
| 146 | + |
| 147 | + asciinema CLI captures the original terminal theme automatically (since |
| 148 | + v3.0). |
| 149 | + |
| 150 | + If you're implementing an asciicast-compatible recorder, then you can |
| 151 | + retrieve the colors from the terminal via OSC sequences (this is how |
| 152 | + asciinema recorder does it). However, you can also use another technique, |
| 153 | + or even hard-code the colors of your favorite theme. |
| 154 | + |
| 155 | +### `timestamp` |
| 156 | + |
| 157 | +Unix timestamp of the beginning of the recording session. |
| 158 | + |
| 159 | +Type: integer |
| 160 | + |
| 161 | +### `idle_time_limit` |
| 162 | + |
| 163 | +Idle time limit, as given via `-i` option to `asciinema rec`. |
| 164 | + |
| 165 | +Type: float |
| 166 | + |
| 167 | +This should be used by an asciicast player to reduce all terminal inactivity |
| 168 | +(delays between frames) to a maximum of `idle_time_limit` value. |
| 169 | + |
| 170 | +### `command` |
| 171 | + |
| 172 | +Command that was recorded, as given via `-c` option to `asciinema rec`. |
| 173 | + |
| 174 | +Type: string |
| 175 | + |
| 176 | +### `title` |
| 177 | + |
| 178 | +Title of the recording, as given via `-t` option to `asciinema rec`. |
| 179 | + |
| 180 | +Type: string |
| 181 | + |
| 182 | +### `env` |
| 183 | + |
| 184 | +A map of captured environment variables. |
| 185 | + |
| 186 | +Type: object (String -> String). |
| 187 | + |
| 188 | +Example env: |
| 189 | + |
| 190 | +```json |
| 191 | +{"SHELL": "/bin/bash", "TERM": "xterm-256color"} |
| 192 | +``` |
| 193 | + |
| 194 | +> Official asciinema recorder captures only `SHELL` variable by default. All |
| 195 | +> implementations of asciicast-compatible terminal recorder should not capture |
| 196 | +> any additional environment variables unless explicitly requested by the user. |
| 197 | +
|
| 198 | +## Event stream |
| 199 | + |
| 200 | +Each element of the event stream is a 3-tuple encoded as JSON array: |
| 201 | + |
| 202 | + [interval, code, data] |
| 203 | + |
| 204 | +Where: |
| 205 | + |
| 206 | +* `interval` (float) - time interval from the previous event (in seconds), |
| 207 | +* `code` (string) - event type code, one of: `"o"`, `"i"`, `"m"`, `"r"` |
| 208 | +* `data` (any) - event specific data, described separately for each event |
| 209 | + code. |
| 210 | + |
| 211 | +For example, let's look at the following line: |
| 212 | + |
| 213 | + [1.001376, "o", "Hello world"] |
| 214 | + |
| 215 | +It represents: |
| 216 | + |
| 217 | +* output (code `o`), |
| 218 | +* of text `Hello world`, |
| 219 | +* which happened `1.001376` sec after the previous event. |
| 220 | + |
| 221 | +### Supported event codes |
| 222 | + |
| 223 | +This section describes the event codes supported in asciicast v3 format. |
| 224 | + |
| 225 | +The list is open to extension, and new event codes may be added in both the |
| 226 | +current and future versions of the format. For example, we may add new event |
| 227 | +code for text overlay (subtitles display). |
| 228 | + |
| 229 | +A tool which interprets the event stream (a player or a post-processor) should |
| 230 | +ignore (or pass through) event codes it doesn't understand or doesn't care |
| 231 | +about. |
| 232 | + |
| 233 | +#### o - output, data written to a terminal |
| 234 | + |
| 235 | +Event with code `"o"` represents printing new data to a terminal. |
| 236 | + |
| 237 | +`data` is a string containing the data that was printed. It must be valid, UTF-8 |
| 238 | +encoded JSON string as described in [JSON RFC section |
| 239 | +2.5](http://www.ietf.org/rfc/rfc4627.txt), with any non-printable Unicode |
| 240 | +codepoints encoded as `\uXXXX`. |
| 241 | + |
| 242 | +Example: |
| 243 | + |
| 244 | +```json |
| 245 | +[5.0, "o", "hello"] |
| 246 | +``` |
| 247 | + |
| 248 | +#### i - input, data read from a terminal |
| 249 | + |
| 250 | +Event with code `"i"` represents character typed in by the user, or more |
| 251 | +specifically, raw data sent from a terminal emulator to stdin of the recorded |
| 252 | +program (usually shell). |
| 253 | + |
| 254 | +`data` is a string containing captured ASCII character representing a key, or a |
| 255 | +control character like `"\r"` (enter), `"\u0001"` (ctrl-a), `"\u0003"` (ctrl-c), |
| 256 | +etc. Like with `"o"` event, it's UTF-8 encoded JSON string, with any |
| 257 | +non-printable Unicode codepoints encoded as `\uXXXX`. |
| 258 | + |
| 259 | +Example: |
| 260 | + |
| 261 | +```json |
| 262 | +[5.0, "i", "h"] |
| 263 | +``` |
| 264 | + |
| 265 | +!!! note |
| 266 | + |
| 267 | + asciinema CLI doesn't capture keyboard input by default. All implementations |
| 268 | + of asciicast-compatible terminal recorder should not capture it either |
| 269 | + unless explicitly requested by the user. |
| 270 | + |
| 271 | +#### m - marker |
| 272 | + |
| 273 | +Event with code `"m"` represents a marker. |
| 274 | + |
| 275 | +[Markers](../cli/markers.md) can act as breakpoints or be used for playback navigation and |
| 276 | +automation. |
| 277 | + |
| 278 | +`data`, which specifies a label, is optional (can be empty string). Labels may |
| 279 | +be used to e.g. create a list of named "chapters". |
| 280 | + |
| 281 | +Example: |
| 282 | + |
| 283 | +```json |
| 284 | +[5.0, "m", ""] // unlabeled marker |
| 285 | +[3.0, "m", "Configuration"] // labeled marker |
| 286 | +``` |
| 287 | + |
| 288 | +#### r - resize |
| 289 | + |
| 290 | +Event with code `"r"` represents terminal resize. |
| 291 | + |
| 292 | +Those are captured in response to `SIGWINCH` signal. |
| 293 | + |
| 294 | +`data` contains new terminal size (columns + rows) formatted as |
| 295 | +`"{COLS}x{ROWS}"`. |
| 296 | + |
| 297 | +```json |
| 298 | +[5.0, "r", "100x50"] |
| 299 | +``` |
| 300 | + |
| 301 | +## File extension |
| 302 | + |
| 303 | +Suggested file extension is `.cast`. |
| 304 | + |
| 305 | +## Media type (MIME) |
| 306 | + |
| 307 | +Suggested media type is `application/x-asciicast`. |
| 308 | + |
| 309 | +## Note on compatibility |
| 310 | + |
| 311 | +asciicast v3 file format is not backward compatible with asciicast v1/v2 due to |
| 312 | +the header schema changes and use of relative time (intervals) in the event |
| 313 | +stream (even though v1 uses relative time too). |
| 314 | + |
| 315 | +However, the changes between v2 and v3 are relatively small when compared with |
| 316 | +the changes between v1 and v2. Both v2 and v3 use the same newline-delimited |
| 317 | +JSON format, with the first line being the header, and the following lines |
| 318 | +being the event stream. Also, aside from time/intervals, both v2 and v3 use the |
| 319 | +same notation and event codes for the event stream. |
| 320 | + |
| 321 | +Support for asciicast v3 has been added in: |
| 322 | + |
| 323 | +* asciinema cli [v3.0](https://github.com/asciinema/asciinema/releases/tag/v3.0.0-rc.4) |
| 324 | +* asciinema player [v3.10.0](https://github.com/asciinema/asciinema-player/releases/tag/v3.10.0-rc.1) |
| 325 | +* asciinema server [v202505xx](https://github.com/asciinema/asciinema-server/releases/tag/v202504xx) |
0 commit comments