Terminal recording with Asciinema

Recently, I had to record a little demo of cd-surfer: A simple TUI file explorer, a terminal app I wrote. Here is the result:

I used Asciinema to record to a .cast file, and Gifcast to convert the .cast file into a .gif file.

Asciinema is the top result when you google “terminal recording”. Despite that, the moment I see it is written in python, I went back to google to find other options. Only to, after much frustration, come back to Asciinema and got the job done in minutes.

I have nothing against python itself, but sometimes, when you have to install a new package, it becomes a dependency hell. A lot of packages depend on a very specific version of its dependencies, and sometimes the new package you want to install depends on an already installed package but on a different version. When that happens, it triggers a snowball effect and everything brakes.

Luckly, there is a asciiname docker container available. It will run in isolation of your system python install. Having docker installed, you can run the command below:

docker run --rm -it -v "${HOME}/.config/asciinema:/root/.config/asciinema" -v "${PWD}:/root/data" --entrypoint=/bin/bash ghcr.io/asciinema/asci
inema

The following command does the following

  • Download and the asciinema container
  • Use ~/.config/asciinema on your host as the configuration file (optional file, will use default options if the file does not exist)
  • Create a volume in the current folder. Which means to you can access files from the current folder from the container´s folder /root/data
  • Open bash shell inside the container
  • Remove the container after you exit

From inside the container you can run:

  • asciinema rec demo.cast To start the recording and save to demo.cast.
  • asciinema rec -c command demo.cast to record a specific command
  • asciinema play demo.cast To play the recorded file on the terminal

After creating the .cast file, you can convert it to a .gif animation with Gifcast

On a side note, Gifcast has a very interesting approach, because it runs entirely on the browser, there is no server processing. It does that by decoding the .cast file and enconding the GIF file client-side (😲) with omggif. By doing that, it can be hosted on Github Pages for free (😎) (Github Pages does not support server code AFAIK).


Publicado

em

por

Comentários

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *