分页: 1 / 1
ansi转tex。 ansi2color.pl
发表于 : 2011-12-26 23:59
由 eexpress
把终端的各种颜色输出,转tex。
比如
代码: 全选
● l ~/bin|head|ansi2color.pl >xxx.tex
然后
Re: ansi转tex。 ansi2color.pl
发表于 : 2011-12-27 11:29
由 eexpress
改成支持 --html --tex 和 --none
其中 --none 是人可读的颜色名
--html --tex 都是管道过滤到文件。
原始图

- term
代码: 全选
● l|ansi2color.pl -h>xxx.html

- html
代码: 全选
● l|ansi2color.pl -t>xxx.tex

- tex
- screenshot19.png (10.07 KiB) 查看 1159 次
Re: ansi转tex。 ansi2color.pl
发表于 : 2011-12-27 11:34
由 eexpress
Many programs that generate colored output detect if they're writing to a TTY, and switch off colors if they aren't. This is because color codes are annoying when you only want to capture the text, so they try to "do the right thing" automatically.
The simplest way to capture color output from a program like that is to tell it to write color even though it's not connected to a TTY. You'll have to read the program's documentation to find out if it has that option. (e.g., grep has the --color=always option.)
You could also use the expect script unbuffer to create a pseudo-tty like this:
echo barney | unbuffer grep barney | sed -n 1,$\ p
Re: ansi转tex。 ansi2color.pl
发表于 : 2011-12-27 12:15
由 eexpress
● git df
diff --git a/ansi2color.pl b/ansi2color.pl
index e3cb441..60d184a 100755
--- a/ansi2color.pl
+++ b/ansi2color.pl
@@ -8,12 +8,15 @@ my @c=qw /black red green yellow blue magenta cyan white/;
my @l;
while(<STDIN>){
+s/\e\[K//g; s/\e\[m/\e\[0m/g;
if($html){
s/\ / /g;
s/\e\[(.*?)m/get_html_color($1)/eg;
s/$/<br>/g;
}elsif($tex){
+ s/\\/\\textbackslash /g;
s/[\#\$\%\&\~\_\{\}]/\\$&/g;
+ s/\^/\\^{}/g;
s/\ /\\hspace{6pt}/g;
s/\e\[(.*?)m/get_tex_color($1)/eg;
s/$/\n/g;
grep的color真捣蛋。
加了3行。
Re: ansi转tex。 ansi2color.pl
发表于 : 2011-12-27 12:32
由 ChenFengyuan
Re: ansi转tex。 ansi2color.pl
发表于 : 2011-12-27 12:32
由 roylez
神又拿天书卖萌
Re: ansi转tex。 ansi2color.pl
发表于 : 2012-01-02 11:31
由 ChenFengyuan
roylez 写了:神又拿天书卖萌
拜见主席
