今天又是一个特殊的日子,也不知为何,老是在这样的日子来写东西,首先得祝大家端午节快乐。今天小编要带给大家一个好东西–asciinema,一款传说中能记录终端会话的工具,重点是能够在视频播放的同时进行复制,读到这里,机制的小伙伴们估计已经清楚的知道其实不是真实的视频。小编在很久以前就得知其分享操作之便利性,幸得今日有空,将之与大家共享,录制视屏并在网页中引用。

官方网站

https://asciinema.org/

使用说明

大家可以在官网注册账号,可以利用官方提供的服务共享视频,不过需要提交资源。虽说官方给出录制的内容默认是私有的,毕竟东西在自己手里放心,万一记录有敏感信息多不好,这里不通过上传来分享。

安装

asciinema支持*nix类系统,甚至在安卓的termux也支持安装。这里以ubuntu为例。

1
2
$ sudo apt-get update
$ sudo apt-get install asciinema

简单地开始使用

录制会话并保存至/tmp/demo.json

1
$ asciinema rec /tmp/demo.json

如果在录制过程中忽略太长时间的滞留状态,可以使用 -i参数设定最长等待时间。

1
$ asciinema rec -i 2.5 /tmp/demo.json

进行回放

1
$ asciinema play /tmp/demo.json

将录制的内容嵌入到网页中

新建一个工作目录,并切换至目录,将录制的内容移动到当前目录

1
2
3
$ mkdir asciinema_stuff
$ cd asciinema_stuff
$ mv /tmp/demo.json .

到asciinema-player指定的发布页面 下载asciinema-player.cssasciinema-player.js两个文件

1
2
$ wget https://github.com/asciinema/asciinema-player/releases/download/v2.6.1/asciinema-player.css
$ wget https://github.com/asciinema/asciinema-player/releases/download/v2.6.1/asciinema-player.js

新建一个示范html文件,展示的就是简单的页面,小伙伴根据自家情况装饰一下。

1
$ vi test.html

核心内容如下

1
2
3
4
5
6
7
8
9
<html>
<head>
  <link rel="stylesheet" type="text/css" href="asciinema-player.css" />
</head>
<body>
  <asciinema-player src="demo.json"></asciinema-player>
  <script src="asciinema-player.js"></script>
</body>
</html>

实例演示