TranslateProject/sources/tech/20180814 How To Record Terminal Sessions As SVG Animations In Linux.md

4.9 KiB
Raw Blame History

How To Record Terminal Sessions As SVG Animations In Linux

Recording Terminal sessions may help in several cases. You can use those recording sessions to document everything that you did in Terminal and save them for future reference. You can use them to demonstrate different Linux commands and its use cases to your juniors, students and anyone who are willing to Learn Linux. Luckily, we have many tools to record Terminal sessions in Unix-like operating systems. We already have featured some of the tools/commands which helps you to record the Terminal sessions in the past. You can go through them in the links given below.

Today, we are going to see yet another tool to record the Terminal activities. Say hello to “Termtosvg”. As the name implies, Termtosvg records your Terminal sessions as standalone SVG animations. It is a simple command line utility written in Python programming language. It generates lightweight and clean looking animations embeddable on a project page. It supports custom color themes, terminal UI and animation controls via SVG templates. It is also compatible with asciinema recording format. Termtosvg supports GNU/Linux, Mac OS and BSD OSes.

Installing Termtosvg

Termtosvg can be installed using PIP, a python package manager to install applications written using Python language. If you havent installed PIP already, refer the following guide.

After installing PIP, run the following command to install Termtosvg tool:

$ pip3 install --user termtosvg

And, install the following prerequisites to render the Terminal screen.

$ pip3 install pyte python-xlib svgwrite

Done. Let us go ahead and generate Terminal sessions in SVG format.

Record Terminal Sessions As SVG Animations In Linux

Recording Terminal sessions using Termtosvg is very simple. Just open your Terminal window and run the following command to start recording it.

$ termtosvg

Note: If you termtosvg command is not available, restart your system once.

You will see the following output after running termtosvg command:

Recording started, enter "exit" command or Control-D to end

You will now be in a sub-shell where you can execute the Linux commands as usual. Everything you do in the Terminal will be recorded.

Let me run a random commands.

$ mkdir mydirectory

$ cd mydirectory/

$ touch file.txt

$ cd ..

$ uname -a

Once youre done, press CTRL+D or type exit to stop recording. The resulting recording will be saved in /tmp folder with a unique name.

You can then open the SVG file in any web browser of your choice from Terminal like below.

$ firefox /tmp/termtosvg_ddkehjpu.svg

You can also directly open the SVG file from browser ( File - > ).

Here is the output of the above recording in my Firefox browser.

Here is some more examples on how to use Termtosvg to record Terminal sessions.

Like I mentioned already, Termtosvg will record a terminal session and save it as an SVG animation file in /tmp directory by default.

However, you can generate an SVG animation with a custom name, for example animation.svg , and save it in a custom location, for example /home/sk/ostechnix/.

$ termtosvg /home/sk/ostechnix/animation.svg

Record a terminal session and render it using a specific template:

$ termtosvg -t ~/templates/my_template.svg

Record a terminal session with a specific screen geometry:

$ termtosvg -g 80x24 animation.svg

Record a terminal session in asciicast v2 format:

$ termtosvg record recording.cast

Render an SVG animation from a recording in asciicast format:

$ termtosvg render recording.cast animation.svg

For more details, refer Termtosvg manual.

And, thats all for now. Hope this was useful. More good stuffs to come. Stay tuned!

Cheers!


via: https://www.ostechnix.com/how-to-record-terminal-sessions-as-svg-animations-in-linux/

作者:SK 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出