Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
drush outputs some ANSI color codes which look ugly.
It can be supported by patching drush_terminal.terminal.inc below:
...
$output = implode("\n", $output);
// Ugly hack to process the color codes
// We need something like Perl's HTML::FromANSI
// http://search.cpan.org/perldoc?HTML%3A%3AFromANSI
// but for PHP
// http://ansilove.sourceforge.net/ only converts to image :(
// Technique below is from:
// http://stackoverflow.com/questions/1375683/converting-ansi-escape-sequences-to-html-using-php/2233231
$output = preg_replace("/\x1B\[31;40m(.*?)(\x1B\[0m)/", '<span style="color: red">$1</span>$2', $output);
$output = preg_replace("/\x1B\[1m(.*?)(\x1B\[0m)/", '<b>$1</b>$2', $output);
$output = preg_replace("/\x1B\[0m/", '', $output);
echo $output;
...
jquery.terminal.js will also have to be patched:
...
var terminal_append = function(data) {
var formattedData = $('' + data + '');
var dataRows = formattedData.html().split(/\n/);
...
However this means all output must be HTML-safe.
Needs some more work to make the HTML escaping conditional.
A quicker workaround is to disable drush colors altogether (--nocolor).