[英]Perl text diff color
我希望能够比较两个文本字符串并显示颜色的差异。 我尝试过String :: Diff但是无法区分显示颜色。 我使用Windows与Active State perl 5,版本12。
编辑:ansi颜色等没有帮助我显示颜色的差异
编辑:这是我想要的结果
$string1 = "This is string 1" ; $string2 = "This is string 2" ; some_diff_cmd($string1,$string2) ;
我想要的输出(以粗体显示的条目应为彩色,表示红色)
###字符串不匹配####
string1 =这是字符串1
string2 =这是字符串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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.