Perl文本diff颜色 [英] Perl text diff color
本文介绍了Perl文本diff颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要能够比较两个文本字符串并显示颜色差异。我尝试 String :: Diff ,但可以没有得到显示的颜色差异。我使用Windows活动状态perl 5,版本12。
I want to be able to compare two text string and display the difference in color. I tried String::Diff but could not get the difference to display in color. I am using Windows with Active State perl 5, version 12.
编辑:ansi颜色等不帮我显示颜色差异
编辑:这是我想要的结果
Edit : the ansi color etc do not help me with displaying the differences in color
Edit : Here is the result I want
$string1 = "This is string 1" ;
$string2 = "This is string 2" ;
some_diff_cmd($string1,$string2) ;
输出我想要的(粗体的输入应该是红色的)
Output I want (the entries in bold should be in color say red)
###字符串不匹配####
### Strings do not match ####
string1 =这是字符串 1
string2 =这是字符串 2
string1 = This is string 1
string2 = This is string 2
推荐答案
如何?
use Win32::Console::ANSI;
use String::Diff qw( diff );
my @strings = (
'This is string 1', 'This is string 2'
);
my $BOLD_RED_MARK = "\e[1;31m"; # or \e[0;31m, if bold is not required
my $RESET_MARK = "\e[0m";
my $diff = String::Diff::diff(@strings,
remove_open => $BOLD_RED_SIGN,
remove_close => $RESET_SIGN,
append_open => $BOLD_RED_SIGN,
append_close => $RESET_SIGN,
);
print $diff->[0], "\n";
print $diff->[1], "\n";
这篇关于Perl文本diff颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文