@@ -30,11 +30,11 @@ public function __construct(?Theme $theme = null, $inlineStyles = true, $charset
30
30
$ this ->inlineStyles = $ inlineStyles ;
31
31
$ this ->charset = $ charset ;
32
32
$ this ->inlineColors = $ this ->theme ->asArray ();
33
- $ this ->colorNames = array (
33
+ $ this ->colorNames = [
34
34
'black ' , 'red ' , 'green ' , 'yellow ' , 'blue ' , 'magenta ' , 'cyan ' , 'white ' ,
35
35
'' , '' ,
36
36
'brblack ' , 'brred ' , 'brgreen ' , 'bryellow ' , 'brblue ' , 'brmagenta ' , 'brcyan ' , 'brwhite ' ,
37
- ) ;
37
+ ] ;
38
38
}
39
39
40
40
public function convert ($ text )
@@ -44,7 +44,7 @@ public function convert($text)
44
44
// remove character set sequences
45
45
$ text = preg_replace ('#\e(\(|\))(A|B|[0-2])# ' , '' , $ text );
46
46
47
- $ text = htmlspecialchars ($ text , PHP_VERSION_ID >= 50400 ? ENT_QUOTES | ENT_SUBSTITUTE : ENT_QUOTES , $ this ->charset );
47
+ $ text = htmlspecialchars ($ text , \ PHP_VERSION_ID >= 50400 ? \ ENT_QUOTES | \ ENT_SUBSTITUTE : \ ENT_QUOTES , $ this ->charset );
48
48
49
49
// carriage return
50
50
$ text = preg_replace ('#^.*\r(?!\n)#m ' , '' , $ text );
@@ -56,7 +56,7 @@ public function convert($text)
56
56
if ('backspace ' == $ token [0 ]) {
57
57
$ j = $ i ;
58
58
while (--$ j >= 0 ) {
59
- if ('text ' == $ tokens [$ j ][0 ] && strlen ( $ tokens [$ j ][1 ]) > 0 ) {
59
+ if ('text ' == $ tokens [$ j ][0 ] && '' !== $ tokens [$ j ][1 ]) {
60
60
$ tokens [$ j ][1 ] = substr ($ tokens [$ j ][1 ], 0 , -1 );
61
61
62
62
break ;
@@ -75,9 +75,9 @@ public function convert($text)
75
75
}
76
76
77
77
if ($ this ->inlineStyles ) {
78
- $ html = sprintf ('<span style="background-color: %s; color: %s">%s</span> ' , $ this ->inlineColors ['black ' ], $ this ->inlineColors ['white ' ], $ html );
78
+ $ html = \ sprintf ('<span style="background-color: %s; color: %s">%s</span> ' , $ this ->inlineColors ['black ' ], $ this ->inlineColors ['white ' ], $ html );
79
79
} else {
80
- $ html = sprintf ('<span class="ansi_color_bg_black ansi_color_fg_white">%s</span> ' , $ html );
80
+ $ html = \ sprintf ('<span class="ansi_color_bg_black ansi_color_fg_white">%s</span> ' , $ html );
81
81
}
82
82
83
83
// remove empty span
@@ -135,75 +135,75 @@ protected function convertAnsiToColor($ansi)
135
135
}
136
136
137
137
// options: bold => 1, dim => 2, italic => 3, underscore => 4, blink => 5, rapid blink => 6, reverse => 7, conceal => 8, strikethrough => 9
138
- if (in_array (1 , $ options ) || $ hi ) { // high intensity equals regular bold
138
+ if (\ in_array (1 , $ options ) || $ hi ) { // high intensity equals regular bold
139
139
$ fg += 10 ;
140
140
// bold does not affect background color
141
141
}
142
142
143
- if (in_array (2 , $ options )) { // dim
143
+ if (\ in_array (2 , $ options )) { // dim
144
144
$ fg = ($ fg >= 10 ) ? $ fg - 10 : $ fg ;
145
145
}
146
146
147
- if (in_array (3 , $ options )) {
147
+ if (\ in_array (3 , $ options )) {
148
148
$ as .= '; font-style: italic ' ;
149
149
$ cs .= ' ansi_color_italic ' ;
150
150
}
151
151
152
- if (in_array (4 , $ options )) {
152
+ if (\ in_array (4 , $ options )) {
153
153
$ as .= '; text-decoration: underline ' ;
154
154
$ cs .= ' ansi_color_underline ' ;
155
155
}
156
156
157
- if (in_array (9 , $ options )) {
157
+ if (\ in_array (9 , $ options )) {
158
158
$ as .= '; text-decoration: line-through ' ;
159
159
$ cs .= ' ansi_color_strikethrough ' ;
160
160
}
161
161
162
- if (in_array (7 , $ options )) {
162
+ if (\ in_array (7 , $ options )) {
163
163
$ tmp = $ fg ;
164
164
$ fg = $ bg ;
165
165
$ bg = $ tmp ;
166
166
}
167
167
}
168
168
169
169
if ($ this ->inlineStyles ) {
170
- return sprintf ('</span><span style="background-color: %s; color: %s%s"> ' , $ this ->inlineColors [$ this ->colorNames [$ bg ]], $ this ->inlineColors [$ this ->colorNames [$ fg ]], $ as );
170
+ return \ sprintf ('</span><span style="background-color: %s; color: %s%s"> ' , $ this ->inlineColors [$ this ->colorNames [$ bg ]], $ this ->inlineColors [$ this ->colorNames [$ fg ]], $ as );
171
171
} else {
172
- return sprintf ('</span><span class="ansi_color_bg_%s ansi_color_fg_%s%s"> ' , $ this ->colorNames [$ bg ], $ this ->colorNames [$ fg ], $ cs );
172
+ return \ sprintf ('</span><span class="ansi_color_bg_%s ansi_color_fg_%s%s"> ' , $ this ->colorNames [$ bg ], $ this ->colorNames [$ fg ], $ cs );
173
173
}
174
174
}
175
175
176
176
protected function tokenize ($ text )
177
177
{
178
- $ tokens = array () ;
179
- preg_match_all ("/(?: \e\[(.*?)m|( \x08))/ " , $ text , $ matches , PREG_OFFSET_CAPTURE );
178
+ $ tokens = [] ;
179
+ preg_match_all ("/(?: \e\[(.*?)m|( \x08))/ " , $ text , $ matches , \ PREG_OFFSET_CAPTURE );
180
180
181
- $ codes = array () ;
181
+ $ codes = [] ;
182
182
$ offset = 0 ;
183
183
foreach ($ matches [0 ] as $ i => $ match ) {
184
184
if ($ match [1 ] - $ offset > 0 ) {
185
- $ tokens [] = array ( 'text ' , substr ($ text , $ offset , $ match [1 ] - $ offset )) ;
185
+ $ tokens [] = [ 'text ' , substr ($ text , $ offset , $ match [1 ] - $ offset )] ;
186
186
}
187
187
188
188
foreach (explode ('; ' , $ matches [1 ][$ i ][0 ]) as $ code ) {
189
189
if ('0 ' == $ code || '' == $ code ) {
190
- $ codes = array () ;
190
+ $ codes = [] ;
191
191
} else {
192
192
// remove existing occurrence to avoid processing duplicate styles
193
- if (in_array ($ code , $ codes ) && ($ key = array_search ($ code , $ codes )) !== false ) {
193
+ if (\ in_array ($ code , $ codes ) && ($ key = array_search ($ code , $ codes )) !== false ) {
194
194
unset($ codes [$ key ]);
195
195
}
196
196
}
197
197
198
198
$ codes [] = $ code ;
199
199
}
200
200
201
- $ tokens [] = array ( "\x08" == $ match [0 ] ? 'backspace ' : 'color ' , implode ('; ' , $ codes )) ;
202
- $ offset = $ match [1 ] + strlen ($ match [0 ]);
201
+ $ tokens [] = [ "\x08" == $ match [0 ] ? 'backspace ' : 'color ' , implode ('; ' , $ codes )] ;
202
+ $ offset = $ match [1 ] + \ strlen ($ match [0 ]);
203
203
}
204
204
205
- if ($ offset < strlen ($ text )) {
206
- $ tokens [] = array ( 'text ' , substr ($ text , $ offset )) ;
205
+ if ($ offset < \ strlen ($ text )) {
206
+ $ tokens [] = [ 'text ' , substr ($ text , $ offset )] ;
207
207
}
208
208
209
209
return $ tokens ;
0 commit comments