Colorized diff output on the shell
Together with Console_Color, it is possible to use Text_Diff to generate colored diffs on an ANSI terminal.
<?php
require_once 'Console/Color.php';
require_once 'Text/Diff.php';
require_once 'Text/Diff/Renderer/inline.php';
$lines1 = file('1.htm');
$lines2 = file('2.htm');
$diff = new Text_Diff('auto', array($lines1, $lines2));
$renderer = new Text_Diff_Renderer_inline(
array(
'ins_prefix' => '%g',
'ins_suffix' => '%n',
'del_prefix' => '%r',
'del_suffix' => '%n',
)
);
echo Console_Color::convert(
htmlspecialchars_decode(
$renderer->render($diff)
)
);
?>
is displayed like that on a shell: