Skip to content

Commit f7aa50d

Browse files
author
Thomas Off
committed
Fix problem with incomplete end sequences
Some terminals seem to not issue the complete end sequence '[0m' for returning to default color, but using a shorthand '[m', which can be fixed with a little tweak of the regular expression.
1 parent 3330118 commit f7aa50d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

SensioLabs/AnsiConverter/AnsiToHtmlConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function convertAnsiToColor($ansi)
8787
{
8888
$bg = 0;
8989
$fg = 7;
90-
if ('0' != $ansi) {
90+
if ('0' != $ansi && '' != $ansi) {
9191
$options = explode(';', $ansi);
9292

9393
foreach ($options as $option) {
@@ -127,7 +127,7 @@ protected function convertAnsiToColor($ansi)
127127
protected function tokenize($text)
128128
{
129129
$tokens = array();
130-
preg_match_all("/(?:\e\[(.+?)m|(\x08))/", $text, $matches, PREG_OFFSET_CAPTURE);
130+
preg_match_all("/(?:\e\[(.*?)m|(\x08))/", $text, $matches, PREG_OFFSET_CAPTURE);
131131

132132
$offset = 0;
133133
foreach ($matches[0] as $i => $match) {

0 commit comments

Comments
 (0)