Fixed --enable-ansi and --disable-ansi not being respected on threads

this causes some breakage to the behaviour of Terminal, and for that reason this is going on 4.0.

Terminal::hasFormattingCodes() will no longer auto-detect whether colour codes are supported.
This commit is contained in:
Dylan K. Taylor
2018-12-29 11:23:32 +00:00
parent 10ac322b8f
commit 498bffb34f
3 changed files with 38 additions and 29 deletions

View File

@ -275,20 +275,18 @@ class MainLogger extends \AttachableThreadedLogger{
$message = sprintf($this->format, $time->format("H:i:s"), $color, $threadName, $prefix, $message);
$this->synchronized(function() use ($message, $level, $time) : void{
$cleanMessage = TextFormat::clean($message);
if(!Terminal::isInit()){
Terminal::init($this->mainThreadHasFormattingCodes); //lazy-init colour codes because we don't know if they've been registered on this thread
}
if($this->mainThreadHasFormattingCodes and Terminal::hasFormattingCodes()){ //hasFormattingCodes() lazy-inits colour codes because we don't know if they've been registered on this thread
echo Terminal::toANSI($message) . PHP_EOL;
}else{
echo $cleanMessage . PHP_EOL;
}
$this->synchronized(function() use ($message, $level, $time) : void{
echo Terminal::toANSI($message) . PHP_EOL;
foreach($this->attachments as $attachment){
$attachment->call($level, $message);
}
$this->logStream[] = $time->format("Y-m-d") . " " . $cleanMessage . PHP_EOL;
$this->logStream[] = $time->format("Y-m-d") . " " . TextFormat::clean($message) . PHP_EOL;
});
}