Liu*_* 刘研 16 html terminal putty copy-paste
我想在学习 Linux 时写笔记(HTML 格式)。当我需要注意彩色终端文本输出时,我希望终端文本的颜色可以保留在我的笔记中,例如:
Note 1: Test
The output of xx command is
<pre>
[root@webserver ~]# ll /
total 100
drwxrwxrwt. 7 root root 4096 8? 24 12:22 <span style='background-color:green; color:blue;'>tmp</span>
drwxr-xr-x. 14 root root 4096 7? 19 21:20 <span style='color:blue;'>usr</span>
</pre>
Run Code Online (Sandbox Code Playgroud)
我可以在纯文本周围手动添加 HTML 代码包装器,但我希望有一种自动的方法来实现这一点。
目前,我在 Windows 上使用 putty 连接到远程 CentOS linux 服务器。
iam*_*amc 19
使用脚本实用程序将终端输出捕获到文件(包括 ansi 颜色控制字符),然后使用ansi2html脚本将其转换为 html 。例如:
inigo:tmp> script
Script started, file is typescript
inigo:tmp> ls
#
# lots of colour output
#
inigo:tmp> exit
exit
Script done, file is typescript
inigo:tmp> cat typescript | ansi2html.sh > typescript.html
Run Code Online (Sandbox Code Playgroud)
如果使用 PuTTY,“所有会话输出”登录选项也将保留 ansi 颜色代码。
作为ansi2html的替代品,您可以使用aha-Ansi HTML Adapter。