install/includes/cli-core.php
changeset 1021 5990ac411f34
parent 1020 0867b9d38c38
child 1081 745200a9cc2a
equal deleted inserted replaced
1020:0867b9d38c38 1021:5990ac411f34
   780   return true;
   780   return true;
   781 }
   781 }
   782 
   782 
   783 function parse_shellcolor_string($str)
   783 function parse_shellcolor_string($str)
   784 {
   784 {
       
   785   // only compute this once (saves some CPU time)
       
   786   static $do_colors = null;
       
   787   if ( $do_colors === null )
       
   788   {
       
   789     $do_colors = ( isset($_SERVER['TERM']) && $_SERVER['TERM'] != 'dumb' );
       
   790   }
       
   791   
   785   $expr = '/<c ((?:[0-9]+)(?:;[0-9]+)*)>([\w\W]*?)<\/c>/';
   792   $expr = '/<c ((?:[0-9]+)(?:;[0-9]+)*)>([\w\W]*?)<\/c>/';
   786   while ( preg_match($expr, $str) )
   793   while ( preg_match($expr, $str) )
   787     $str = preg_replace($expr, "\x1B[\\1m\\2\x1B[0m", $str);
   794     $str = $do_colors ? preg_replace($expr, "\x1B[\\1m\\2\x1B[0m", $str) : preg_replace($expr, "\\2", $str);
   788   
   795   
   789   return $str;
   796   return $str;
   790 }
   797 }
   791 
   798