Skip to content

Commit de5ed7a

Browse files
committed
Handle style reset sequences
1 parent 62572d1 commit de5ed7a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

SensioLabs/AnsiConverter/AnsiToHtmlConverter.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function convertAnsiToColor($ansi)
9999
if ('0' != $ansi && '' != $ansi) {
100100
$options = explode(';', $ansi);
101101

102-
foreach ($options as $option) {
102+
foreach ($options as $key => $option) {
103103
if ($option >= 30 && $option < 38) {
104104
$fg = $option - 30;
105105
} elseif ($option >= 40 && $option < 48) {
@@ -108,6 +108,22 @@ protected function convertAnsiToColor($ansi)
108108
$fg = 7;
109109
} elseif (49 == $option) {
110110
$bg = 0;
111+
} elseif ($option >= 22 && $option < 30) { // 21 has varying effects, best to ignored it
112+
$unset = $option - 20;
113+
114+
foreach ($options as $i => $v) {
115+
if ($v == $unset) {
116+
unset($options[$i]);
117+
}
118+
119+
if (2 == $unset && 1 == $v) { // 22 also unsets bold
120+
unset($options[$i]);
121+
}
122+
123+
if ($i >= $key) { // do not unset options after current position in parent loop
124+
break;
125+
}
126+
}
111127
}
112128
}
113129

0 commit comments

Comments
 (0)