@@ -267,8 +267,7 @@ public static function escapeshellcmd($cmd)
267
267
/**
268
268
* Prepares token content for output to screen.
269
269
*
270
- * Replaces invisible characters so they are visible. On non-Windows
271
- * operating systems it will also colour the invisible characters.
270
+ * Replaces invisible characters so they are visible, and colour them.
272
271
*
273
272
* @param string $content The content to prepare.
274
273
* @param string[] $exclude A list of characters to leave invisible.
@@ -278,35 +277,24 @@ public static function escapeshellcmd($cmd)
278
277
*/
279
278
public static function prepareForOutput ($ content , $ exclude =[])
280
279
{
281
- if (stripos (PHP_OS , 'WIN ' ) === 0 ) {
282
- if (in_array ("\r" , $ exclude , true ) === false ) {
283
- $ content = str_replace ("\r" , '\r ' , $ content );
284
- }
285
-
286
- if (in_array ("\n" , $ exclude , true ) === false ) {
287
- $ content = str_replace ("\n" , '\n ' , $ content );
288
- }
289
-
290
- if (in_array ("\t" , $ exclude , true ) === false ) {
291
- $ content = str_replace ("\t" , '\t ' , $ content );
292
- }
293
- } else {
294
- if (in_array ("\r" , $ exclude , true ) === false ) {
295
- $ content = str_replace ("\r" , "\033[30;1m \\r \033[0m " , $ content );
296
- }
280
+ if (in_array ("\r" , $ exclude , true ) === false ) {
281
+ $ content = str_replace ("\r" , "\033[30;1m \\r \033[0m " , $ content );
282
+ }
297
283
298
- if (in_array ("\n" , $ exclude , true ) === false ) {
299
- $ content = str_replace ("\n" , "\033[30;1m \\n \033[0m " , $ content );
300
- }
284
+ if (in_array ("\n" , $ exclude , true ) === false ) {
285
+ $ content = str_replace ("\n" , "\033[30;1m \\n \033[0m " , $ content );
286
+ }
301
287
302
- if (in_array ("\t" , $ exclude , true ) === false ) {
303
- $ content = str_replace ("\t" , "\033[30;1m \\t \033[0m " , $ content );
304
- }
288
+ if (in_array ("\t" , $ exclude , true ) === false ) {
289
+ $ content = str_replace ("\t" , "\033[30;1m \\t \033[0m " , $ content );
290
+ }
305
291
292
+ if (stripos (PHP_OS , 'WIN ' ) !== 0 ) {
293
+ // Printing Unicode characters like '·' to Windows console only works since PHP 7.1.
306
294
if (in_array (' ' , $ exclude , true ) === false ) {
307
295
$ content = str_replace (' ' , "\033[30;1m· \033[0m " , $ content );
308
296
}
309
- }//end if
297
+ }
310
298
311
299
return $ content ;
312
300
0 commit comments