将ANSI转义(终端格式/颜色代码)转换为HTML的库 [英] A library to convert ANSI escapes (terminal formatting/color codes) to HTML
问题描述
我正在寻找一个代码库,通过纯文本标签或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
)
< 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
将转换转换为< br />没有必要,它只是我不知道的转义码。我可以自己一起破解它,但是我可能会错过重要的东西,比如下划线或弄乱背景颜色的工作方式。我宁愿坐在别人的代码之上。
这样的工具(命令行linux)还是库(最好是perl,python或ruby)存在?
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:
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?
There seems to be an HTML::FromANSI Perl module.
这篇关于将ANSI转义(终端格式/颜色代码)转换为HTML的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!