Example #1
0
 protected function stylizeDiff($diff)
 {
     $lineRegexToColor = array('/^(\\s*Index\\: .+)$/' => array(static::COLOR_CODE_YELLOW, null), '/^(\\=+(\\s*))$/' => array(static::COLOR_CODE_GRAY, null), '/^(\\+{3}\\s+.*)$/' => array(static::COLOR_CODE_WHITE, null), '/^(\\-{3}\\s+.*)$/' => array(static::COLOR_CODE_WHITE, null), '/^(\\+.*)$/' => array(static::COLOR_CODE_GREEN, null), '/^(-.*)$/' => array(static::COLOR_CODE_RED, null), '/^(@@ .+ @@).*$/' => array(static::COLOR_CODE_TEAL, null));
     $bashStyling = new BashStyling();
     foreach ($lineRegexToColor as $regex => $colors) {
         if (preg_match($regex, $diff, $match)) {
             list($foreground, $background) = $colors;
             $count = 1;
             $diff = str_replace($match[1], $bashStyling->normal($match[1], $foreground, $background, true), $diff, $count);
             break;
         }
     }
     return $diff;
 }
Example #2
0
 public function testBold()
 {
     $styling = new Styling();
     $normal = trim($styling->bold("foo", 33, null, true));
     $this->assertSame("foo", $normal);
 }
Example #3
0
 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;
 }