NSI codes to HTML converter
deansi的Python项目详细描述
功能
- 它可以用作模块或命令行工具。
- 支持大多数“m”代码(颜色和属性)。
- 外观可以使用样式定制,非常方便
强大的方式。
- ANSI属性映射到可设置样式的HTML类 (ansi_yellow,ansi_bright…)
- 包含具有相同ANSI属性集的文本序列 在一个激活了这些类的span中。
- 可以为类或特定组合定义样式 课程
- 您可以根据封闭容器定义样式,以便 不同的样式可以在一个文档中共存。
- 它已经过测试驱动开发和回溯测试。
用作python模块
- deansi.styleSheet():返回ANSI的默认样式表 可以自定义的类。
- deansi.deansi(consoleText):返回HTML转换
下面的示例使用它们来构建 输出:
importdeansihtml_template="""\ <style> .ansi_terminal {{ background-color: #222; color: #cfc; }} {defaultStyle} </style> <div class="ansi_terminal">{ansiText}</div> """ansiInput="\033[31mHello World!!\033[m"printhtml_template.format(defaultStyle=deansi.styleSheet(),ansiText=deansi.deansi(ansiInput),)
命令行使用
deansi可以用作基于管道的命令行工具。很简单的 使用,可以是:
$ ls --color | deansi.py > ls.html
此外,我们还可以使用一些选项来修改它的行为:
$ deansy.py --help usage: deansi.py [-h][-s FILE][-t FILE][--dark][INPUT_FILE][OUTPUT_FILE] Converts coloured console output into equivalent HTML positional arguments: INPUT_FILE the console input to convert (default stdin) OUTPUT_FILE the file where to drop the html output (default stdout) optional arguments: -h, --help show this help message and exit -s FILE, --style FILE use FILE as stylesheet -t FILE, --template FILE use FILE as html template --dark use the dark background style
自定义样式表
默认样式表如下:
.ansi_terminal{background-color:#222;color:#cfc;}.ansi_terminal{white-space:pre;font-family:monospace;}.ansi_black{color:black;}.ansi_red{color:darkred;}.ansi_green{color:darkgreen;}.ansi_yellow{color:orange;}.ansi_blue{color:darkblue;}.ansi_magenta{color:purple;}.ansi_cyan{color:darkcyan;}.ansi_white{color:lightgray;}.ansi_bright.ansi_black{color:gray;}.ansi_bright.ansi_red{color:red;}.ansi_bright.ansi_green{color:green;}.ansi_bright.ansi_yellow{color:yellow;}.ansi_bright.ansi_blue{color:blue;}.ansi_bright.ansi_magenta{color:magenta;}.ansi_bright.ansi_cyan{color:cyan;}.ansi_bright.ansi_white{color:white;}.ansi_bgblack{background-color:black;}.ansi_bgred{background-color:red;}.ansi_bggreen{background-color:green;}.ansi_bgyellow{background-color:yellow;}.ansi_bgblue{background-color:blue;}.ansi_bgmagenta{background-color:magenta;}.ansi_bgcyan{background-color:cyan;}.ansi_bgwhite{background-color:white;}.ansi_bright{font-weight:bold;}.ansi_faint{opacity:.5;}.ansi_italic{font-style:italic;}.ansi_underscore{text-decoration:underline;}.ansi_blink{text-decoration:blink;}.ansi_reverse{border:1ptsolid;}.ansi_hide{opacity:0;}.ansi_strike{text-decoration:line-through;}
因为css的级联行为 默认值将覆盖这些值。例如,如果你想 应用ansi bright属性时更改黄色,而不是 应用粗体,您可以说:
.ansi_yellow.ansi_bright{color:#FF7;font-weight:inherit;}
如果你想在同一个html中有几个行为,你可以使用css魔术 像这样:
.my_own_ansi_enviroment.ansi_inverse{font-style:italic;border:none;}