termtosvg and get the resulting SVG file as soon as you enter the exit() command. We'll see in a few paragraphs why I want to generate an intermediary .cast file.
Pretty cool, heh?
Okay, my terminal settings are not that fancy, so let's throw glitter in your eyes.
image::/assets/images/2021/08/20/glitter.svg[glitter]
Now we're talking! This "cast" has been generated with the very same command. So the command once you enter exit()will create a .cast file which will then be used to generate a SVG file (with termtosvg) or a GIF file with the asciicast2gif command.
=== How to generate the resulting SVG file
Next mandatory step: generate the SVG file. Commands do not come any simpler:
----termtosvg render glitter.cast glitter.svg----
Afterwards, you just have to move your file wherever you need it and link/import it into your documentation.
You're welcome.
Now, why the hell did I generate an intermediary .castfile? Well, that format can be used as an input for another project, link:https://github.com/asciinema/asciicast2gif[asciicast2gif], which is part of link:https://github.com/asciinema/asciinema[asciinema]. Asciinema uses the same .cast format as termtosvg, so we can generate SVG from asciinema cast files, GIF files from termtosvg castfiles, and the other way around.
Now, what if you're out of luck, and termtosvg is not available on your distro? Let's try to build it by ourselves:
== Compile and install termtosvg
----bash
git clone https://github.com/nbedos/termtosvg.git && cd termtosvg/
== Prerequisites, use apt, apt-get, yum, whatever package manager you have on your system
sudo apt-get install -y libxml2-dev libxslt-dev python3 python3-dev python3-pip python3-setuptools
make build
== If you ever have an error saying that python is not available, you could make an horrible hack like
== sudo ln -s /usr/bin/python3 /usr/bin/python or anything smarter
== Now, let's install it. Note that 1.1.0-py3 is the version that was available at the time I wrote this blog post, your
== mileage may vary
pip3 install dist/termtosvg-1.1.0-py3-none-any.whl
<figure>
<img src="https://bruno.verachten.fr/assets/images/2021/08/20/great%20success.gif" alt="great success" />
</figure>
Now itβs your turn to produce good looking shell recordings with termtosvg.