public function testBold() { $styling = new Styling(); $normal = trim($styling->bold("foo", 33, null, true)); $this->assertSame("[1m[38;5;33mfoo[0m", $normal); }
public function getOutput(array $requestedNumbers = null) { $bashStyling = new BashStyling(); $statusLines = $this->svnStatus; $fileNumber = 1; $outputLines = array(); $maxColumns = $this->svnNumber->getBashCommand()->getMaxTerminalColumns() - self::COLUMN_INDENTATION_COUNT_FILEPATH; $filePathPaddingRight = min(self::COLUMN_DEFAULT_COUNT - self::COLUMN_INDENTATION_COUNT_FILEPATH, $maxColumns); $stagedFilePaths = $this->staging->getStagedFilePaths(); foreach ($statusLines as $line) { if ($match = $this->validateLine($line)) { if ($requestedNumbers && false == in_array($fileNumber, $requestedNumbers)) { $line = ""; $fileNumber++; continue; } $filePath = str_pad(str_replace("\\", "/", $match[2]), $filePathPaddingRight); $backgroundColor = null; if ($fileNumber % 2 == 0) { $backgroundColor = static::COLOR_CODE_GRAY_DARK; } $line = trim($line); $stagedIndicator = " "; if (in_array(trim($filePath), $stagedFilePaths)) { $stagedIndicator = $bashStyling->normal("\$", static::COLOR_CODE_GREEN); } $replacedLine = $bashStyling->bold($stagedIndicator . str_pad($fileNumber, 4, " ", STR_PAD_LEFT) . " ", null, $backgroundColor); $padding = $bashStyling->normal(str_repeat(" ", substr_count(str_pad($match[1], 5), " ")), null, $backgroundColor, true); switch (preg_replace('/\\s+/', ' ', strtoupper($match[1]))) { case "A +": $match[1] = "A+"; case "A": case "A+": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_GREEN, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_GREEN, $backgroundColor); break; case "D C": $replacedLine .= $bashStyling->bold("D", static::COLOR_CODE_RED, $backgroundColor) . $bashStyling->bold("C", static::COLOR_CODE_ORANGE, $backgroundColor) . " " . $bashStyling->escape() . $bashStyling->normal($filePath, static::COLOR_CODE_ORANGE, $backgroundColor); break; case "C": case "!": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_ORANGE, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_ORANGE, $backgroundColor); break; case "D": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_RED, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_RED, $backgroundColor); break; case "E": case "G": case "I": case "X": case "?": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_GRAY_LIGHT, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_GRAY_LIGHT, $backgroundColor); break; case "L": case "~": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_YELLOW, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_YELLOW, $backgroundColor); break; case "M": case "R": $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_BLUE, $backgroundColor) . $padding . $bashStyling->normal($filePath, static::COLOR_CODE_BLUE, $backgroundColor); break; default: $replacedLine .= $bashStyling->bold($match[1], static::COLOR_CODE_WHITE, $backgroundColor) . $padding . $filePath; break; } $outputLines[] = $bashStyling->escape($replacedLine); $fileNumber++; } else { if (preg_match('/^\\s+\\>\\s+(.+)$/', $line, $match)) { $leftHandStr = str_repeat(" ", self::COLUMN_INDENTATION_COUNT_FILEPATH + 1) . "> "; $line = $leftHandStr . str_replace("\\", "/", $match[1]); $outputLines[] = $bashStyling->normal(str_pad($line, min(self::COLUMN_DEFAULT_COUNT, $maxColumns)), static::COLOR_CODE_WHITE, $backgroundColor, true); } else { $outputLines[] = $bashStyling->escape() . $bashStyling->normal(str_pad(str_replace("\\", "/", $line), min(self::COLUMN_DEFAULT_COUNT, $maxColumns)), null, null, true); } } } if ($outputLines) { array_unshift($outputLines, ""); $outputLines[] = ""; } $output = implode(PHP_EOL, $outputLines); return $output; }