Merge pull request #9932 from pinewall/submit-tech20180814

submit tech/20180814 How To Record Terminal Sessions As SVG Animations In Linux.md
This commit is contained in:
Xingyu.Wang 2018-08-23 20:11:24 +08:00 committed by GitHub
commit 52d0865672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 134 additions and 141 deletions

View File

@ -1,141 +0,0 @@
pinewall translating
How To Record Terminal Sessions As SVG Animations In Linux
======
![](https://www.ostechnix.com/wp-content/uploads/2018/08/termtosvg-720x340.png)
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.
+ [How To Record Everything You Do In Terminal][3]
+ [Asciinema Record Terminal Sessions And Share Them On The Web][4]
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][1]. 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.
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-action-1-1.png)
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 - > <path-to-svg>**).
Here is the output of the above recording in my Firefox browser.
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-browser.gif)
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**][2].
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][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://nbedos.github.io/termtosvg/pages/templates.html
[2]:https://github.com/nbedos/termtosvg/blob/develop/man/termtosvg.md
[3]: https://www.ostechnix.com/record-everything-terminal/
[4]: https://www.ostechnix.com/asciinema-record-terminal-sessions-share-web/

View File

@ -0,0 +1,134 @@
将 Linux 终端会话录制成 SVG 动画
======
![Banner 图](https://www.ostechnix.com/wp-content/uploads/2018/08/termtosvg-720x340.png)
录制终端会话可以满足我们不同类型的需求。通过录制终端会话,你可以完整记录你在终端中执行的操作,将其保存可供后续参考。通过录制终端会话,你还可以向青少年、学生或其它打算学习 Linux 的人展示各种 Linux 命令及其用例。值得庆幸的是,市面上已经有不少工具,可以帮助我们在类 Unix 操作系统下录制终端会话。我们已经介绍过一些可以帮助你录制终端会话的工具,可以在下面的链接中找到。
+ [如何录制你在终端中的所作所为][3]
+ [Asciinema 录制终端会话并在网上分享][4]
今天,我们要介绍另一款录制终端操作的工具,名字叫做 **Termtosvg**。从名字可以看出Termtosvg 将你的终端会话录制成一个单独的 SVG 动画。它是一款简单的命令行工具,使用 **Python** 语言编写可以生成轻量级、外观整洁的动画可以嵌入到网页项目中。Termtosvg 支持自定义<ruby>色彩主题<rt>color themes</rt>、终端 UI还可以通过 [SVG 模板][1]完成动画控制。它兼容 asciinema 录制格式,支持 GNU/LinuxMac OS 和 BSD 等操作系统。
### 安装 Termtosvg
PIP 是一个面向 Python 语言编写的软件包的管理器,可以用于安装 Termtosvg。如果你没有安装 PIP可以参考下面的指导
[如何使用 PIP 管理 Python 软件包][5]
安装 PIP 后,运行如下命令安装 Termtosvg 工具:
```
$ pip3 install --user termtosvg
```
此外,还要安装渲染终端屏幕所需的依赖包:
```
$ pip3 install pyte python-xlib svgwrite
```
安装完毕,我们接下来生成 SVG 格式的终端会话。
### 将 Linux 终端会话录制成 SVG 动画
使用 Termtosvg 录制终端会话十分容易。打开终端窗口,运行如下命令即可开始录制:
```
$ termtosvg
```
**注意:** 如果 termtosvg 命令不可用,重启操作系统一次即可。
运行 termtosvg 命令后,可以看到如下命令输出:
```
Recording started, enter "exit" command or Control-D to end
```
你目前位于一个子 Shell 中,在这里可以像平常那样输入命令。你在终端中的所作所为都会被录制。
不妨随便输入一些命令:
```
$ mkdir mydirectory
$ cd mydirectory/
$ touch file.txt
$ cd ..
$ uname -a
```
操作完成后,使用组合键 **CTRL+D** 或者输入 **exit** 停止录制。录制结果将会保存在 **/tmp** 目录,(由于做了唯一性处理)文件名并不会重复。
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-action-1-1.png)
现在,你可以在命令行运行命令,使用你的浏览器打开 SVG 文件:
```
$ firefox /tmp/termtosvg_ddkehjpu.svg
```
你也可以在(图形界面的)浏览器中直接打开这个 SVG 文件( **File -> <SVG 文件路径>** )。
我用 Firefox 浏览器打开的效果如下:
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Termtosvg-in-browser.gif)
下面举例说明几种使用 Termtosvg 录制终端会话的方式。
我刚刚提到Termtosvg 录制终端会话后默认保存成 **/tmp** 目录下的一个 SVG 动画文件。
但你可以指定 SVG 动画文件的文件名,例如 **animation.svg**;也可以指定一个存放路径,例如 **/home/sk/ostechnix/**。
```
$ termtosvg /home/sk/ostechnix/animation.svg
```
录制终端会话并使用特定模板进行渲染:
```
$ termtosvg -t ~/templates/my_template.svg
```
使用指定的<ruby>屏幕参数<rt>screen geometry</rt></ruby>录制终端会话:
```
$ termtosvg -g 80x24 animation.svg
```
使用 asciicast v2 格式录制终端会话:
```
$ termtosvg record recording.cast
```
将 asciicast 格式的录制结果渲染成 SVG 动画:
```
$ termtosvg render recording.cast animation.svg
```
欲了解更多细节,请参考 [**Termtosvg 手册**][2]。
好了,本次分享就到这里,希望对你有帮助。更多精彩内容,敬请期待!
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-record-terminal-sessions-as-svg-animations-in-linux/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[pinewall](https://github.com/pinewall)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://nbedos.github.io/termtosvg/pages/templates.html
[2]:https://github.com/nbedos/termtosvg/blob/develop/man/termtosvg.md
[3]:https://www.ostechnix.com/record-everything-terminal/
[4]:https://www.ostechnix.com/asciinema-record-terminal-sessions-share-web/
[5]:https://www.ostechnix.com/manage-python-packages-using-pip/