Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Add support for asciicast v2 recording format
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedos committed Jun 24, 2018
1 parent 37c6a38 commit 49c7874
Show file tree
Hide file tree
Showing 116 changed files with 1,528 additions and 2,147 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.PHONY: usage tests venv_dev xresources build deploy_test deploy_prod
.PHONY: usage tests venv_dev xresources build deploy_test deploy_prod examples

VENV_PATH=.venv
VENV_ACTIVATE=. $(VENV_PATH)/bin/activate
EXAMPLES_DIR=examples
CASTS_DIR=$(EXAMPLES_DIR)/casts

.DEFAULT: usage

Expand All @@ -10,6 +12,7 @@ usage:
@echo " make build # Build source distribution archives"
@echo " make deploy_prod # Upload source distribution archives to pypi.org"
@echo " make deploy_test # Upload source distribution archives to test.pypi.org"
@echo " make examples # Render example SVG animations"
@echo " make tests # Run unit tests"
@echo " make xresources # Update Xresources data from the base16-xresources repository"

Expand Down Expand Up @@ -40,3 +43,11 @@ venv_dev: setup.py

xresources:
./termtosvg/data/Xresources/update.sh

examples:
$(VENV_ACTIVATE) && \
for cast_file in $$(find $(CASTS_DIR) -name '*.cast'); do \
svg_file="$(EXAMPLES_DIR)/$$(basename --suffix=.cast $$cast_file).svg" && \
termtosvg render "$$cast_file" "$$svg_file"; \
done

74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[![Build Status](https://travis-ci.org/nbedos/termtosvg.svg?branch=develop)](https://travis-ci.org/nbedos/termtosvg)
[![Build Status](https://travis-ci.org/nbedos/termtosvg.svg?branch=master)](https://travis-ci.org/nbedos/termtosvg)

# termtosvg
A Linux terminal recorder written in Python which renders your command
line sessions as standalone SVG animations.

<p align="center">
<img src="https://cdn.rawgit.com/nbedos/termtosvg/develop/examples/htop.svg">
<img src="https://cdn.rawgit.com/nbedos/termtosvg/0.2.0/examples/awesome.svg">
</p>

More examples [here](https://github.com/nbedos/termtosvg/tree/develop/examples)
More examples of recordings [here](https://github.com/nbedos/termtosvg/blob/0.2.0/examples/examples.md)

## Motivation
I really like the clean look of SVG animations and I also wanted to see
Expand All @@ -30,20 +30,7 @@ $ termtosvg
Recording started, enter "exit" command or Control-D to end
```

You are now in a subshell where you can type your commands as usual:

```
$ ls
build examples LICENSE README.md termtosvg tests
dist htmlcov Makefile setup.py termtosvg.egg-info
$ wc -l termtosvg/*py
279 termtosvg/anim.py
0 termtosvg/__init__.py
94 termtosvg/__main__.py
403 termtosvg/term.py
776 total
```

You are now in a subshell where you can type your commands as usual.
Once you are done, exit the shell to end the recording:

```
Expand All @@ -55,6 +42,49 @@ Finally, use your favorite image viewer to play the animation:
$ xdg-open /tmp/termtosvg_exp5nsr4.svg
```

### Subcommands
Rendering the SVG animation while recording might sometimes slow the
commands being executed a bit because of the CPU usage, so it is
possible to proceed in two steps:
1. Record the terminal session to disk in asciicast v2 format
2. Render the SVG animation using the recording on disk

The usage of these two commands is detailed below.

#### Record
```
$ termtosvg record --help
usage: termtosvg record [output_file] [--verbose] [--help]
record the session to a file in asciicast v2 format
positional arguments:
output_file optional filename for the recording; if missing, a random
filename will be automatically generated
optional arguments:
-h, --help show this help message and exit
-v, --verbose increase log messages verbosity
```
#### Render
```
$ termtosvg render --help
usage: termtosvg render input_file [output_file] [--theme THEME] [--verbose] [--help]
render an asciicast recording as an SVG animation
positional arguments:
input_file recording of the terminal session in asciicast v2 format
output_file optional filename for the SVG animation; if missing, a random
filename will be automatically generated
optional arguments:
-h, --help show this help message and exit
--theme THEME color theme used to render the terminal session (circus,
classic-dark, classic-light, dracula, isotope, marrakesh,
material, monokai, solarized-dark, solarized-light, zenburn)
-v, --verbose increase log messages verbosity
```
### Color themes
#### Default themes
If you wish to record a terminal session using a specific color theme, say
Expand All @@ -63,13 +93,17 @@ monokai for example, enter the following command:
termtosvg --theme monokai
```

Available themes can be listed by omitting the name of the theme:
Available themes can be listed with `termtosvg --help`
```
termtosvg --theme
...
--theme THEME color theme used to render the terminal session (circus,
classic-dark, classic-light, dracula, isotope, marrakesh,
material, monokai, solarized-dark, solarized-light, zenburn)
...
```

#### Custom themes
If termtosvg is called without the '--theme' option, it will try gathering
If termtosvg is called without the `--theme` option, it will try gathering
color information from the Xserver running on your machine.

To tell the Xserver about the color theme you wish to use for termtosvg,
Expand Down
5 changes: 0 additions & 5 deletions examples/alsamixer.svg

This file was deleted.

5 changes: 5 additions & 0 deletions examples/awesome.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions examples/casts/awesome.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{"version": 2, "width": 82, "height": 19, "theme": {"fg": "#839496", "bg": "#002b36", "palette": "#073642:#dc322f:#859900:#b58900:#268bd2:#d33682:#2aa198:#eee8d5:#002b36:#cb4b16:#586e75:#657b83:#839496:#6c71c4:#93a1a1:#fdf6e3"}}
[0.0, "o", "\u001b[1;31mnico \u001b[0;34m~\u001b[1;31m $ \u001b[0m"]
[0.390644, "o", "t"]
[0.534149, "o", "e"]
[0.60612, "o", "r"]
[0.710178, "o", "m"]
[1.078342, "o", "t"]
[1.189929, "o", "o"]
[1.534438, "o", "s"]
[1.678299, "o", "v"]
[1.845896, "o", "g"]
[2.045981, "o", "\r\n"]
[2.31268, "o", "Recording started, enter \"exit\" command or Control-D to end\r\n"]
[2.335253, "o", "\u001b[1;31mnico \u001b[0;34m~\u001b[1;31m $ \u001b[0m"]
[2.919678, "o", "f"]
[3.057802, "o", "o"]
[3.156814, "o", "r"]
[3.329286, "o", " "]
[3.817869, "o", "i"]
[4.105399, "o", " "]
[4.305461, "o", "i"]
[4.401502, "o", "n"]
[4.673821, "o", " "]
[5.105561, "o", "{"]
[5.417739, "o", "0"]
[5.657291, "o", "."]
[5.785598, "o", "."]
[5.9372, "o", "1"]
[6.897622, "o", "0"]
[7.185106, "o", "}"]
[7.82563, "o", ";"]
[8.122953, "o", " "]
[8.225456, "o", "d"]
[8.329534, "o", "o"]
[8.9059, "o", "\r\n"]
[8.909192, "o", "> "]
[9.440506, "o", "e"]
[9.641043, "o", "c"]
[9.760405, "o", "h"]
[9.848853, "o", "o"]
[10.05707, "o", " "]
[10.176479, "o", "\""]
[10.496724, "o", "t"]
[10.656585, "o", "e"]
[10.712681, "o", "r"]
[10.841119, "o", "m"]
[10.969162, "o", "t"]
[11.088708, "o", "o"]
[11.200516, "o", "s"]
[11.376936, "o", "v"]
[11.561196, "o", "g"]
[11.689687, "o", " "]
[11.840507, "o", "i"]
[11.952808, "o", "s"]
[12.073014, "o", " "]
[12.21684, "o", "a"]
[12.416843, "o", "w"]
[12.616769, "o", "e"]
[13.152913, "o", "s"]
[13.264964, "o", "o"]
[13.321029, "o", "m"]
[13.512938, "o", "e"]
[13.672984, "o", "!"]
[14.032879, "o", "\""]
[15.273311, "o", "\r\n"]
[15.275364, "o", "> "]
[15.976472, "o", "d"]
[16.072913, "o", "o"]
[16.128381, "o", "n"]
[16.272398, "o", "e"]
[16.529055, "o", " "]
[17.096251, "o", "|"]
[17.328895, "o", " "]
[17.599234, "o", "l"]
[17.665076, "o", "o"]
[17.856983, "o", "l"]
[17.98452, "o", "c"]
[18.064621, "o", "a"]
[18.272265, "o", "t"]
[19.216768, "o", "\r\n"]
[19.307438, "o", "\u001b[38;5;63mt\u001b[39m\u001b[38;5;63me\u001b[39m\u001b[38;5;63mr\u001b[39m\u001b[38;5;63mm\u001b[39m"]
[19.308384, "o", "\u001b[38;5;69mt\u001b[39m\u001b[38;5;33mo\u001b[39m\u001b[38;5;33ms\u001b[39m\u001b[38;5;33mv\u001b[39m\u001b[38;5;33mg\u001b[39m\u001b[38;5;33m \u001b[39m\u001b[38;5;33mi\u001b[39m\u001b[38;5;33ms\u001b[39m\u001b[38;5;33m \u001b[39m\u001b[38;5;33ma\u001b[39m\u001b[38;5;39mw\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39mo\u001b[39m\u001b[38;5;39mm\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39m!\u001b[39m\u001b[38;5;39m\u001b[39m\r\n\u001b[38;5;63mt\u001b[39m\u001b[38;5;69me\u001b[39m\u001b[38;5;33mr\u001b[39m\u001b[38;5;33mm\u001b[39m\u001b[38;5;33mt\u001b[39m\u001b[38;5;33mo\u001b[39m\u001b[38;5;33ms\u001b[39m\u001b[38;5;33mv\u001b[39m\u001b[38;5;33mg\u001b[39m\u001b[38;5;33m \u001b[39m\u001b[38;5;33mi\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39ma\u001b[39m\u001b[38;5;39mw\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39mo\u001b[39m\u001b[38;5;39mm\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;38m!\u001b[39m\u001b[38;5;38m\u001b[39m\r\n\u001b[38;5;33mt\u001b[39m\u001b[38;5;33me\u001b[39m\u001b[38;5;33mr\u001b[39m\u001b[38;5;33mm\u001b[39m"]
[19.30845, "o", "\u001b[38;5;33mt\u001b[39m\u001b[38;5;33mo\u001b[39m\u001b[38;5;33ms\u001b[39m\u001b[38;5;33mv\u001b[39m\u001b[38;5;39mg\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39mi\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39ma\u001b[39m\u001b[38;5;39mw\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;38mo\u001b[39m\u001b[38;5;38mm\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44m!\u001b[39m\u001b[38;5;44m\u001b[39m\r\n\u001b[38;5;33mt\u001b[39m\u001b[38;5;33me\u001b[39m\u001b[38;5;33mr\u001b[39m\u001b[38;5;33mm\u001b[39m\u001b[38;5;33mt\u001b[39m\u001b[38;5;39mo\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39mv\u001b[39m\u001b[38;5;39mg\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39mi\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39ma\u001b[39m\u001b[38;5;38mw\u001b[39m\u001b[38;5;38me\u001b[39m\u001b[38;5;44ms"]
[19.312437, "o", "\u001b[39m\u001b[38;5;44mo\u001b[39m"]
[19.314078, "o", "\u001b[38;5;44mm\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44m!\u001b[39m\u001b[38;5;44m\u001b[39m\r\n\u001b[38;5;33mt\u001b[39m\u001b[38;5;33me\u001b[39m\u001b[38;5;39mr\u001b[39m\u001b[38;5;39mm\u001b[39m\u001b[38;5;39mt\u001b[39m\u001b[38;5;39mo\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39mv\u001b[39m\u001b[38;5;39mg\u001b[39m\u001b[38;5;39m \u001b[39m\u001b[38;5;39mi\u001b[39m\u001b[38;5;38ms\u001b[39m\u001b[38;5;38m \u001b[39m\u001b[38;5;44ma\u001b[39m\u001b[38;5;44mw\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44mo\u001b[39m\u001b[38;5;44mm\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44m!\u001b[39m\u001b[38;5;44m\u001b[39m\r\n\u001b[38;5;39mt\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39mr\u001b[39m\u001b[38;5;39mm\u001b[39m\u001b[38;5;39mt\u001b[39m\u001b[38;5;39mo\u001b[39m\u001b[38;5;39ms\u001b[39m\u001b[38;5;39mv\u001b[39m\u001b[38;5;38mg\u001b[39m\u001b[38;5;38m \u001b[39m\u001b[38;5;44mi\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44ma\u001b[39m\u001b[38;5;44mw\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44mo\u001b[39m\u001b[38;5;44mm\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;43m!\u001b[39m\u001b[38;5;49m\u001b[39m\r\n\u001b[38;5;39mt\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;39mr\u001b[39m\u001b[38;5;39mm\u001b[39m\u001b[38;5;39mt\u001b[39m\u001b[38;5;38mo\u001b[39m\u001b[38;5;38ms\u001b[39m\u001b[38;5;44mv\u001b[39m\u001b[38;5;44mg\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44mi\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44ma\u001b[39m\u001b[38;5;44mw\u001b[39m\u001b[38;5;44me\u001b["]
[19.31967, "o", "39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;43mo\u001b[39m\u001b[38;5;49mm\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49m!\u001b[39m\u001b[38;5;49m\u001b[39m\r\n\u001b[38;5;39mt\u001b[39m\u001b[38;5;39me\u001b[39m\u001b[38;5;38mr\u001b[39m\u001b[38;5;38mm\u001b[39m\u001b[38;5;44mt\u001b[39m\u001b[38;5;44mo\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44mv\u001b[39m\u001b[38;5;44mg\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44mi\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44ma\u001b[39m\u001b[38;5;43mw\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49mo\u001b[39m\u001b[38;5;49mm\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49m!\u001b[39m\u001b[38;5;49m\u001b[39m\r\n\u001b[38;5;38mt\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44mr\u001b[39m\u001b[38;5;44mm\u001b[39m\u001b[38;5;44mt\u001b[39m\u001b[38;5;44mo\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44mv\u001b[39m\u001b[38;5;44mg\u001b[39m\u001b[38;5;44m \u001b[39m\u001b[38;5;44mi\u001b[39m\u001b[38;5;43ms\u001b[39m\u001b[38;5;49m \u001b[39m\u001b[38;5;49ma\u001b[39m\u001b[38;5;49mw\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49mo\u001b[39m\u001b[38;5;49mm\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49m!\u001b[39m\u001b[38;5;49m\u001b[39m\r\n\u001b[38;5;44mt\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44mr\u001b[39m\u001b[38;5;44mm\u001b[39m\u001b[38;5;44mt\u001b[39m\u001b[38;5;44mo\u001b[39m\u001b[38;5;44ms\u001b[39m\u001b[38;5;44mv\u001b[39m\u001b[38;5;43mg\u001b[39m\u001b[38;5;49m \u001b[39m\u001b[38;5;49mi\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49m \u001b[39m\u001b[38;5;49m"]
[19.323298, "o", "a\u001b[39m\u001b[38;5;49mw\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49mo\u001b[39m\u001b[38;5;49mm\u001b[39m\u001b[38;5;48me\u001b[39m\u001b[38;5;48m!\u001b[39m\u001b[38;5;48m\u001b[39m\r\n\u001b[38;5;44mt\u001b[39m\u001b[38;5;44me\u001b[39m\u001b[38;5;44mr\u001b[39m\u001b[38;5;44mm\u001b[39m\u001b[38;5;44mt\u001b[39m\u001b[38;5;43mo\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49mv\u001b[39m\u001b[38;5;49mg\u001b[39m\u001b[38;5;49m \u001b[39m\u001b[38;5;49mi\u001b[39m\u001b[38;5;49ms\u001b[39m\u001b[38;5;49m \u001b[39m\u001b[38;5;49ma\u001b[39m\u001b[38;5;49mw\u001b[39m\u001b[38;5;49me\u001b[39m\u001b[38;5;48ms\u001b[39m\u001b[38;5;48mo\u001b[39m\u001b[38;5;48mm\u001b[39m\u001b[38;5;48me\u001b[39m\u001b[38;5;48m!\u001b[39m\u001b[38;5;48m\u001b[39m\r\n\u001b[m\u001b[?25h\u001b[?1;5;2004l\u001b[1;31mnico \u001b[0;34m~\u001b[1;31m $ \u001b[0m"]
[22.490234, "o", "e"]
[22.737309, "o", "x"]
[22.889771, "o", "i"]
[23.009438, "o", "t"]
[23.761836, "o", "\r\nexit\r\n"]
[23.836601, "o", "Recording ended, SVG animation is /tmp/termtosvg__20rwx67.svg\r\n"]
[23.836602, "o", "\u001b[1;31mnico \u001b[0;34m~\u001b[1;31m $ \u001b[0m"]
[26.349826, "o", ""]
Loading

0 comments on commit 49c7874

Please sign in to comment.