Skip to content

Commit

Permalink
Merge pull request #93 from wp-cli/placeholder-character-colorize
Browse files Browse the repository at this point in the history
Use a more impossible placeholder pattern in `Colors::colorize()`
  • Loading branch information
danielbachhuber committed Jan 1, 2016
2 parents c6f72ea + 99aefde commit d0564da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cli/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ static public function colorize($string, $colored = null) {
return $return;
}

$string = str_replace('%%', '% ', $string);
$string = str_replace('%%', '%¾', $string);

foreach (self::getColors() as $key => $value) {
$string = str_replace($key, self::color($value), $string);
}

$string = str_replace('% ', '%', $string);
$string = str_replace('%¾', '%', $string);
self::cacheString($passed, $string, $colored);

return $string;
Expand Down
29 changes: 29 additions & 0 deletions tests/test-table-ascii.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ public function testTableWithPercentCharacters() {
| % at start | at end % | in % middle |
+------------+----------+-------------+

OUT;
$this->assertInOutEquals(array($headers, $rows), $output);
}

/**
* Test that a % is appropriately padded in the table
*/
public function testTablePaddingWithPercentCharacters() {
$headers = array( 'ID', 'post_title', 'post_name' );
$rows = array(
array(
3,
'10%',
''
),
array(
1,
'Hello world!',
'hello-world'
),
);
$output = <<<'OUT'
+----+--------------+-------------+
| ID | post_title | post_name |
+----+--------------+-------------+
| 3 | 10% | |
| 1 | Hello world! | hello-world |
+----+--------------+-------------+

OUT;
$this->assertInOutEquals(array($headers, $rows), $output);
}
Expand Down

0 comments on commit d0564da

Please sign in to comment.