欠下的债早晚是要还的,查文档,重验证,出结果,不误导css
在上一篇文章Asciinema:你的全部操做都将被录制中有两个地方表述有错误或瑕疵,这里更正一下html
第一个地方为录制时的参数--stdin
,参数的意思是启用标准输入录制,原文中说看不到效果,可能官方还未支持,实际上官方已经支持了,且查看录制文件内容时能够看到区别,如下两个对比的例子来讲明linux
例一:执行下方的命令进行录制,录制开始以后执行ssh命令输入密码链接另外一台主机web
asciinema rec ops-coffee.cast
执行asciinema cat
命令查看执行命令bash
# asciinema cat ops-coffee.cast root@onlinegame:~# ssh root@192.168.106.192 ls ops-coffee.cn root@192.168.106.192's password: ops-coffee.cn root@onlinegame:~# exit exit
打印录制的文件内容以下:ssh
# cat ops-coffee.cast {"version": 2, "width": 237, "height": 55, "timestamp": 1574060513, "env": {"SHELL": "/bin/bash", "TERM": "linux"}} [0.012221, "o", "root@onlinegame:~# "] [0.607184, "o", "exit"] [1.07092, "o", "\b\b\b\bssh root@192.168.106.192 ls ops-coffee.cn"] [1.703405, "o", "\r\n"] [1.762974, "o", "root@192.168.106.192's password: "] [4.550759, "o", "\r\n"] [4.558138, "o", "ops-coffee.cn\r\n"] [4.559187, "o", "root@onlinegame:~# "] [5.182817, "o", "e"] [5.582643, "o", "x"] [5.838648, "o", "i"] [6.03067, "o", "t"] [6.759346, "o", "\r\nexit\r\n"]
例二:执行一样的命令,加上--stdin
参数oop
asciinema rec --stdin ops-coffee.1.cast
执行asciinema cat
命令查看执行命令post
# asciinema cat ops-coffee.1.cast root@onlinegame:~# ssh root@192.168.106.192 ls ops-coffee.cn root@192.168.106.192's password: ops-coffee.cn root@onlinegame:~# exit exit
此次再看录制文件的内容:编码
# cat ops-coffee.1.cast {"version": 2, "width": 237, "height": 55, "timestamp": 1574060808, "env": {"SHELL": "/bin/bash", "TERM": "linux"}} [0.01012, "o", "root@onlinegame:~# "] [1.654752, "i", "\u001b[A"] [1.654971, "o", "exit"] [2.014568, "i", "\u001b[A"] [2.014727, "o", "\b\b\b\bssh root@192.168.106.192 ls ops-coffee.cn"] [3.7185, "i", "\r"] [3.719167, "o", "\r\n"] [3.781231, "o", "root@192.168.106.192's password: "] [5.198467, "i", "s"] [5.542343, "i", "m"] [5.774451, "i", "i"] [5.85435, "i", "l"] [5.990628, "i", "e"] [6.342587, "i", "\r"] [6.342817, "o", "\r\n"] [6.351245, "o", "ops-coffee.cn\r\n"] [6.351475, "o", "root@onlinegame:~# "] [7.182384, "i", "e"] [7.182585, "o", "e"] [7.461976, "i", "x"] [7.462183, "o", "x"] [7.543019, "i", "i"] [7.543306, "o", "i"] [7.686868, "i", "t"] [7.68703, "o", "t"] [7.87045, "i", "\r"] [7.871348, "o", "\r\nexit\r\n"]
会发如今实际执行命令彻底一致的状况下,录像文件与上一个没有加--stdin
时的不同,其中就多了输入密码的记录smile
url
且在asciinema文件IO流信息的第二个字段不只有了o
,还有i
的出现,上一篇文章讲到o
是一个固定字符串不知道做用,通过深刻查询确认,IO信息流的第二个字段就是固定string字符串,且只会是i
或o
之间的一种,分别表示stdin
标准输入或stdout
标准输出
--stdin
的效果不管是经过asciinema play
命令播放或是asciinema cat
命令查看都是没法察觉的,在实现WebSSH录像回放时又对录像文件进行了深刻研究,最终发现问题,这里查漏补缺,予以更正,对于以前的错误,深表歉意
asciinema录制文件在web端播放是经过asciinema-player
组件来实现的,使用也是很是的简单
分别引入css和js文件,添加一个asciinema-player
的标签便可播放标签内文件的录像
<html> <head> ... <link rel="stylesheet" type="text/css" href="/asciinema-player.css" /> ... </head> <body> ... <asciinema-player src="/ops-coffee.cast"></asciinema-player> ... <script src="/asciinema-player.js"></script> </body> </html>
asciinema-player标签内能够添加以下一些属性:
cols: 播放终端的列数,默认为80,若是cast文件的header头有设置width
,这里无需设置
rows: 播放终端的行数,默认为24,若是cast文件的header头有设置height
,这里无需设置
autoplay: 是否自动开始播放,默认不会自动播放
preload: 预加载,若是你想为录像配音,这里能够预加载声音
loop: 是否循环播放,默认不循环
start-at: 从哪一个地方开始播放,能够是123
这样的秒数或者是1:06
这样的时间点
speed: 播放的速度,相似于play命令播放时的-s
参数
idle-time-limit: 最大空闲秒数,相似于play命令播放时的-i
参数
poster: 播放以前的预览,能够是npt:1:06
这样给定时间点的画面,也能够是data:text/plain,ops-coffee.cn
这样给定的文字,其中文字支持ANSI编码,例如能够给文字加上颜色data:text/plain,\x1b[1;32mops-coffee.cn\x1b[1;0m
font-size: 文字大小,能够是small
、medium
、big
或者直接是14px
这样的css样式大小
theme: 终端颜色主题,默认是asciinema
,也提供有tango
、solarized-dark
、solarized-light
或者monokai
可选择,固然你也能够自定义主题
还有几个参数title、author、author-url、author-img-url分别表示了录像的标题、做者、做者的主页、做者的头像,这些配置会在全屏观看录像时显示在标题栏中,像下边这样
最后使用如下参数设置asciinema-player,看看播放的效果
<asciinema-player id="play" title="WebSSH Record" author="ops-coffee.cn" author-url="https://ops-coffee.cn" author-img-url="/static/img/logo.png" src="/static/record/ops-coffee.cast" speed="3" idle-time-limit="2" poster="data:text/plain,\x1b[1;32m2019-11-18 16:26:18\x1b[1;0m用户\x1b[1;32madmin\x1b[1;0m链接主机\x1b[1;32m192.168.106.101:22\x1b[1;0m的录像记录"> </asciinema-player>
播放效果以下
同时asciinema-player播放时还支持如下快捷键的使用
space
空格,播放或暂停f
全屏播放,能够看到title等设置←
/ →
快进或快退,每次5秒0,1,6 ... 9
跳转到录像的0%,10%,60% ... 90%<
/ >
增长或下降播放速度,play的-s
参数相关文章推荐阅读: