asciinema可让您轻松录制终端会话,并在终端和网络浏览器中重播。
1. asciinema
逛Github的项目时候,看到一个Readme中,有使用记录终端会话的工具,寻摸着找到了asciinema (使用Python开发的),安装和使用了下,很赞!!
虽然使用场景仅针对终端环境,但对运维或者相关命令行记录很方便,基于纯文本存储,生成的文件大小比纯视频记录要小得多,以下为分享内容!
2. 快速使用
2.1. 安装
其他平台或源码安装可以参见:https://asciinema.org/docs/installation
2.2. 基本命令和使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| $ asciinema
auth -- link install ID with asciinema.org account
cat -- dump full output of recorded session
play -- play back recorded session
rec -- record session
upload -- upload recorded session
$ asciinema --help
usage: asciinema [-h] [--version] {rec,play,cat,upload,auth} ...
example usage:
Record terminal and upload it to asciinema.org:
asciinema rec
Record terminal to local file:
asciinema rec demo.cast
Record terminal and upload it to asciinema.org, specifying title:
asciinema rec -t "My git tutorial"
Record terminal to local file, limiting idle time to max 2.5 sec:
asciinema rec -i 2.5 demo.cast
Replay terminal recording from local file:
asciinema play demo.cast
Replay terminal recording hosted on asciinema.org:
asciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8
Print full output of recorded session:
asciinema cat demo.cast
|
2.3. 生成的cast文件,是unicode编码的纯文本文件
1
2
3
4
5
6
7
8
9
10
11
| [9.09627, "o", "\r\u001b[0m\u001b[27m\u001b[24m\u001b[J\r\n\u001b[01;32m/data/github.com/tkstorm/awesome-data\u001b[00m on \u001b[35m master\u001b[31m!\u001b[00m ⌚ \u001b[01;31m20:14:08\u001b[00m\r\n$ \u001b[K"]
[9.096518, "o", "\u001b[?1h\u001b=\u001b[?2004h"]
[9.802737, "o", "#\u001b[33m step1 record\u001b[39m\u001b[13D"]
[10.023242, "o", "\b#\u001b[39m "]
[10.173313, "o", "\u001b[39ms"]
[10.385989, "o", "\u001b[39mt"]
[10.4693, "o", "\u001b[39me"]
[10.609464, "o", "\u001b[39mp"]
[10.799795, "o", "\u001b[39m2\u001b[33m \u001b[33mf\u001b[33mi\u001b[33mn\u001b[33mi\u001b[33ms\u001b[33mh\u001b[33m, ctrl-d\u001b[39m\u001b[15D"]
[11.110442, "o", "\u001b[39m "]
[12.322484, "o", "\u001b[39mp\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[13D"]
|
3. 分享和展示
3.1. asciinema上传后,会生成分享连接
3.2. 嵌入方式(支持Html、Markdown、内嵌播放器)
1
2
3
4
5
6
7
8
9
10
11
| HTML,支持链接href,在asciinema.org官网打开:
<a target="_blank" href="https://asciinema.org/a/Jxm2xa1EAZEaohDP3816av5is?speed=5"><img src="https://asciinema.org/a/iieA3f7eqr3P8swc0dGaRXWHK.png" width="500"/></a>
Markdown:
[![asciicast](https://asciinema.org/a/14.png)](https://asciinema.org/a/14)
附加选项,:
<a href="https://asciinema.org/a/14?autoplay=1"><img src="https://asciinema.org/a/14.png" width="836"/></a>
嵌入播放器,注意id和src的设置:
<script src="https://asciinema.org/a/Jxm2xa1EAZEaohDP3816av5is.js" id="asciicast-Jxm2xa1EAZEaohDP3816av5is" data-speed="5" data-theme="monokai" data-rows="20" async></script>
|
3.3. 参数支持
播放器支持几种控制行为和外观的选项。将它们附加到URL(?speed=2&theme=tango)或在embed脚本(data-speed=“2” data-theme=“tango”)上将它们设置为数据属性。
支持诸如t、autoplay、preload、loop、speed、size、theme、cols、rows参数,细节可以参见参考链接
4. 嵌入播放器效果 - Amazing
asciinema.org域名可能被屏蔽
5. 参考链接