I'm looking for a code library that converts ANSI escape sequences into HTML color, via plain tags or CSS. For example, something that would convert this:
我正在寻找一个代码库,通过普通标签或CSS将ANSI转义序列转换成HTML颜色。举个例子,一些东西可以转换这个
ESC[00mESC[01;34mbinESC[00m ESC[01;34mcodeESC[00m ESC[01;31mdropbox-lnx.x86-0.6.404.tar.gzESC[00m ESC[00mfooESC[00m
Into this:
到这个:
<span style="color:blue">bin</span>
<span style="color:blue">code</span>
<span style="color:red">dropbox-lnx.x86-0.6.404.tar.gz</span>
foo
Converting breaks into <br/> isn't necessary, it's just the escape codes that I don't know. I could hack it together myself, but I'd probably miss something important like underlines or mess up how background colors work. I'd rather just sit on top of someone else's code.
转换为
不是必须的,只是转义码我不知道。我可以自己把它拼凑在一起,但我可能会漏掉一些重要的东西,比如下划线或弄乱背景颜色是如何工作的。我宁愿坐在别人的代码上面。
Does such a tool (command line linux) or library (perl, python, or ruby preferably) exist?
这样的工具(命令行linux)或库(最好是perl、python或ruby)存在吗?
3 个解决方案
#2
76
aha
is a C-language program, available in an Ubuntu package, at http://ziz.delphigl.com/tool_aha.php or on github https://github.com/theZiz/aha, that takes an input with terminal colors by pipe or file and puts a (w3c conform) HTML-File in stdout. Example:
aha是一个c语言程序,可以在Ubuntu包中找到,可以在http://ziz.delphigl.com/tool_aha.php或github上找到,它通过管道或文件接收带有终端颜色的输入,并在stdout中放入(w3c标准的)html文件。例子:
ls --color=always | aha > ls-output.htm
or
或
ls --color=always | aha --black > ls-output.htm
for a terminal-like look with black background.
以黑色为背景的终极风格。
Compile it by "make" and put it where ever you want.
通过“make”编译它,并把它放在任何你想要的地方。
It would be great to get Feedback. ;-)
如果能得到反馈就太好了。:-)
#3
13
Mature Python library and command line tool which is still maintained: ralphbean/ansi2html
仍然维护的成熟的Python库和命令行工具:ralphbean/ansi2html
Alternatively, for the Bourne shell: ansi2html.sh
或者,对于Bourne shell: ansi2html.sh
#1
#2
76
aha
is a C-language program, available in an Ubuntu package, at http://ziz.delphigl.com/tool_aha.php or on github https://github.com/theZiz/aha, that takes an input with terminal colors by pipe or file and puts a (w3c conform) HTML-File in stdout. Example:
aha是一个c语言程序,可以在Ubuntu包中找到,可以在http://ziz.delphigl.com/tool_aha.php或github上找到,它通过管道或文件接收带有终端颜色的输入,并在stdout中放入(w3c标准的)html文件。例子:
ls --color=always | aha > ls-output.htm
or
或
ls --color=always | aha --black > ls-output.htm
for a terminal-like look with black background.
以黑色为背景的终极风格。
Compile it by "make" and put it where ever you want.
通过“make”编译它,并把它放在任何你想要的地方。
It would be great to get Feedback. ;-)
如果能得到反馈就太好了。:-)
#3
13
Mature Python library and command line tool which is still maintained: ralphbean/ansi2html
仍然维护的成熟的Python库和命令行工具:ralphbean/ansi2html
Alternatively, for the Bourne shell: ansi2html.sh
或者,对于Bourne shell: ansi2html.sh