@@ -30,11 +30,11 @@ public function __construct(?Theme $theme = null, $inlineStyles = true, $charset
3030 $ this ->inlineStyles = $ inlineStyles ;
3131 $ this ->charset = $ charset ;
3232 $ this ->inlineColors = $ this ->theme ->asArray ();
33- $ this ->colorNames = array (
33+ $ this ->colorNames = [
3434 'black ' , 'red ' , 'green ' , 'yellow ' , 'blue ' , 'magenta ' , 'cyan ' , 'white ' ,
3535 '' , '' ,
3636 'brblack ' , 'brred ' , 'brgreen ' , 'bryellow ' , 'brblue ' , 'brmagenta ' , 'brcyan ' , 'brwhite ' ,
37- ) ;
37+ ] ;
3838 }
3939
4040 public function convert ($ text )
@@ -44,7 +44,7 @@ public function convert($text)
4444 // remove character set sequences
4545 $ text = preg_replace ('#\e(\(|\))(A|B|[0-2])# ' , '' , $ text );
4646
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 );
4848
4949 // carriage return
5050 $ text = preg_replace ('#^.*\r(?!\n)#m ' , '' , $ text );
@@ -56,7 +56,7 @@ public function convert($text)
5656 if ('backspace ' == $ token [0 ]) {
5757 $ j = $ i ;
5858 while (--$ j >= 0 ) {
59- if ('text ' == $ tokens [$ j ][0 ] && strlen ( $ tokens [$ j ][1 ]) > 0 ) {
59+ if ('text ' == $ tokens [$ j ][0 ] && '' !== $ tokens [$ j ][1 ]) {
6060 $ tokens [$ j ][1 ] = substr ($ tokens [$ j ][1 ], 0 , -1 );
6161
6262 break ;
@@ -75,9 +75,9 @@ public function convert($text)
7575 }
7676
7777 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 );
7979 } 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 );
8181 }
8282
8383 // remove empty span
@@ -135,75 +135,75 @@ protected function convertAnsiToColor($ansi)
135135 }
136136
137137 // 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
139139 $ fg += 10 ;
140140 // bold does not affect background color
141141 }
142142
143- if (in_array (2 , $ options )) { // dim
143+ if (\ in_array (2 , $ options )) { // dim
144144 $ fg = ($ fg >= 10 ) ? $ fg - 10 : $ fg ;
145145 }
146146
147- if (in_array (3 , $ options )) {
147+ if (\ in_array (3 , $ options )) {
148148 $ as .= '; font-style: italic ' ;
149149 $ cs .= ' ansi_color_italic ' ;
150150 }
151151
152- if (in_array (4 , $ options )) {
152+ if (\ in_array (4 , $ options )) {
153153 $ as .= '; text-decoration: underline ' ;
154154 $ cs .= ' ansi_color_underline ' ;
155155 }
156156
157- if (in_array (9 , $ options )) {
157+ if (\ in_array (9 , $ options )) {
158158 $ as .= '; text-decoration: line-through ' ;
159159 $ cs .= ' ansi_color_strikethrough ' ;
160160 }
161161
162- if (in_array (7 , $ options )) {
162+ if (\ in_array (7 , $ options )) {
163163 $ tmp = $ fg ;
164164 $ fg = $ bg ;
165165 $ bg = $ tmp ;
166166 }
167167 }
168168
169169 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 );
171171 } 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 );
173173 }
174174 }
175175
176176 protected function tokenize ($ text )
177177 {
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 );
180180
181- $ codes = array () ;
181+ $ codes = [] ;
182182 $ offset = 0 ;
183183 foreach ($ matches [0 ] as $ i => $ match ) {
184184 if ($ match [1 ] - $ offset > 0 ) {
185- $ tokens [] = array ( 'text ' , substr ($ text , $ offset , $ match [1 ] - $ offset )) ;
185+ $ tokens [] = [ 'text ' , substr ($ text , $ offset , $ match [1 ] - $ offset )] ;
186186 }
187187
188188 foreach (explode ('; ' , $ matches [1 ][$ i ][0 ]) as $ code ) {
189189 if ('0 ' == $ code || '' == $ code ) {
190- $ codes = array () ;
190+ $ codes = [] ;
191191 } else {
192192 // 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 ) {
194194 unset($ codes [$ key ]);
195195 }
196196 }
197197
198198 $ codes [] = $ code ;
199199 }
200200
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 ]);
203203 }
204204
205- if ($ offset < strlen ($ text )) {
206- $ tokens [] = array ( 'text ' , substr ($ text , $ offset )) ;
205+ if ($ offset < \ strlen ($ text )) {
206+ $ tokens [] = [ 'text ' , substr ($ text , $ offset )] ;
207207 }
208208
209209 return $ tokens ;
0 commit comments