sh/bash/dash/ksh/zsh等Shell脚本
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#2
帖子
由 eexpress » 2011-12-27 11:29
改成支持 --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) 查看 1154 次
-
附件
-
- ansi2color.tar
- (10 KiB) 已下载 52 次
● 鸣学
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#3
帖子
由 eexpress » 2011-12-27 11:34
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
● 鸣学
-
eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
#4
帖子
由 eexpress » 2011-12-27 12:15
● 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行。
● 鸣学
-
roylez
- 帖子: 1928
- 注册时间: 2005-10-04 10:59
- 来自: 上海
#6
帖子
由 roylez » 2011-12-27 12:32
神又拿天书卖萌