private function trimOutputLine($line, $lineNumber)
{
if (strlen($line) < 80) {
return $line;
}
$positionsWordColor = [];
$positionsResetColor = [];
$parts = [];
$lastPos = 0;
//iterate over all WORD_COLORs and save the positions into $positionsWordColor
while (($lastPos = mb_strpos($line, static::WORD_COLOR, $lastPos)) !== false) {
$positionsWordColor[] = $lastPos;
$lastPos = $lastPos + mb_strlen(static::WORD_COLOR);
}
$lastPos = 0;
//iterate over all RESET_COLORs and save the positions into $positionsResetColor
while (($lastPos = mb_strpos($line, static::RESET_COLOR, $lastPos)) !== false) {
$positionsResetColor[] = $lastPos;
$lastPos = $lastPos + mb_strlen(static::RESET_COLOR);
}
foreach ($positionsWordColor as $pos) {
do {
$pos2 = array_shift($positionsResetColor);
} while ($pos2 < $pos);
$pos -= static::SPACE_BEFORE;
$pos2 += static::SPACE_AFTER;
$part = ' ' . $lineNumber . static::COLON_COLOR . ':' . static::RESET_COLOR;
$part .= $pos + static::SPACE_BEFORE . static::COLON_COLOR . ':' . static::RESET_COLOR;
$part .= ' ' . mb_substr($line, $pos, $pos2 - $pos) . static::RESET_COLOR;
$parts[] = $part;
}
return implode(PHP_EOL, $parts);
}