2011-11-29 12:17:55 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Set of classes to help with test output and such. Right now pretty specific
|
|
|
|
|
* to the parser tests but could be more useful one day :)
|
|
|
|
|
*
|
2012-06-14 12:25:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
2012-10-02 20:24:33 +00:00
|
|
|
* @ingroup Maintenance Testing
|
2017-12-01 10:02:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup TermColorer TermColorer
|
|
|
|
|
* @ingroup Maintenance Testing
|
2011-11-29 12:17:55 +00:00
|
|
|
* @todo Fixme: Make this more generic
|
2017-12-01 10:02:26 +00:00
|
|
|
*
|
|
|
|
|
* Set of classes to help with test output and such. Right now pretty specific
|
|
|
|
|
* to the parser tests but could be more useful one day :)
|
2011-11-29 12:17:55 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-06-14 12:25:13 +00:00
|
|
|
/**
|
|
|
|
|
* Terminal that supports ANSI escape sequences.
|
2012-10-02 20:24:33 +00:00
|
|
|
*
|
2017-12-01 10:02:26 +00:00
|
|
|
* @ingroup TermColorer
|
2012-06-14 12:25:13 +00:00
|
|
|
*/
|
2011-11-29 12:17:55 +00:00
|
|
|
class AnsiTermColorer {
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct() {
|
2011-11-29 12:17:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return ANSI terminal escape code for changing text attribs/color
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param string $color Semicolon-separated list of attribute/color codes
|
|
|
|
|
* @return string
|
2011-11-29 12:17:55 +00:00
|
|
|
*/
|
|
|
|
|
public function color( $color ) {
|
|
|
|
|
global $wgCommandLineDarkBg;
|
|
|
|
|
|
|
|
|
|
$light = $wgCommandLineDarkBg ? "1;" : "0;";
|
|
|
|
|
|
|
|
|
|
return "\x1b[{$light}{$color}m";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return ANSI terminal escape code for restoring default text attributes
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @return string
|
2011-11-29 12:17:55 +00:00
|
|
|
*/
|
|
|
|
|
public function reset() {
|
|
|
|
|
return $this->color( 0 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 12:25:13 +00:00
|
|
|
/**
|
|
|
|
|
* A colour-less terminal
|
2012-10-02 20:24:33 +00:00
|
|
|
*
|
2017-12-01 10:02:26 +00:00
|
|
|
* @ingroup TermColorer
|
2012-06-14 12:25:13 +00:00
|
|
|
*/
|
2011-11-29 12:17:55 +00:00
|
|
|
class DummyTermColorer {
|
|
|
|
|
public function color( $color ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reset() {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|