Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions blink/internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func Report(w io.Writer, results []runner.FileResult, isFixer bool) int {
return 1
}

// Footer prints an ECS-style run summary: files scanned, time and memory.
// Footer prints an ECS-style run summary: files scanned, time and memory,
// greyed and preceded by a blank line.
func Footer(w io.Writer, files int, d time.Duration, memBytes uint64) {
_, _ = fmt.Fprintf(w, " // %d files · %s · %d MB\n", files, formatElapsed(d), memBytes/(1024*1024))
f := newFormatter(w)
line := fmt.Sprintf(" // %d files · %s · %d MB", files, formatElapsed(d), memBytes/(1024*1024))
_, _ = fmt.Fprintf(w, "\n%s\n", f.grey(line))
}

// formatElapsed shows seconds past 5s, milliseconds below.
Expand Down Expand Up @@ -197,6 +200,7 @@ func (f formatter) bg(s string, fg, bg int) string {
}

func (f formatter) comment(s string) string { return f.fg(s, 33) } // yellow
func (f formatter) grey(s string) string { return f.fg(s, 37) } // light grey, matches PHP
func (f formatter) bold(s string) string {
if !f.color {
return s
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ private function printRunFooter(int $filesCount, float $startTime): void
? sprintf('%.2f s', $elapsedMilliseconds / 1000)
: sprintf('%dms', $elapsedMilliseconds);

$this->easyCodingStandardStyle->newLine();
$this->easyCodingStandardStyle->writeln(
sprintf(' // %d files · %s · %d MB', $filesCount, $elapsedTime, $peakMemoryMegabytes)
sprintf('<fg=grey> // %d files · %s · %d MB</>', $filesCount, $elapsedTime, $peakMemoryMegabytes)
);
}
}
10 changes: 10 additions & 0 deletions src/Console/Style/EasyCodingStandardStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Symplify\EasyCodingStandard\Console\Style;

use Entropy\Console\Enum\Color;
use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\OutputPrinter;
use Entropy\Console\Output\ProgressBar;
use Symplify\EasyCodingStandard\SniffRunner\ValueObject\Error\CodingStandardError;
Expand All @@ -20,6 +22,7 @@
public function __construct(
private OutputPrinter $outputPrinter,
private ProgressBar $progressBar,
private OutputColorizer $outputColorizer,
private bool $isDebug = false,
) {
}
Expand Down Expand Up @@ -113,6 +116,13 @@ private function normalizeTags(string $text): string
$text = (string) preg_replace('#<comment>(.*?)</comment>#su', '<fg=yellow>$1</>', $text);
$text = (string) preg_replace('#<info>(.*?)</info>#su', '<fg=green>$1</>', $text);

// grey is not handled by OutputColorizer::colorize(), apply it directly
$text = (string) preg_replace_callback(
'#<fg=grey>(.*?)</>#su',
fn (array $matches): string => $this->outputColorizer->color($matches[1], Color::GREY),
$text
);

// normalize explicit closing tags (e.g. </fg=green>) to the generic closing tag
return (string) preg_replace('#</fg=[a-z]+>#', '</>', $text);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Console/Style/EasyCodingStandardStyleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
public function create(): EasyCodingStandardStyle
{
$outputPrinter = new OutputPrinter(new OutputColorizer());
$outputColorizer = new OutputColorizer();
$outputPrinter = new OutputPrinter($outputColorizer);
$progressBar = new ProgressBar();

$isDebug = in_array('--debug', $_SERVER['argv'] ?? [], true);

return new EasyCodingStandardStyle($outputPrinter, $progressBar, $isDebug);
return new EasyCodingStandardStyle($outputPrinter, $progressBar, $outputColorizer, $isDebug);
}
}
8 changes: 6 additions & 2 deletions tests/Console/Style/EasyCodingStandardStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ final class EasyCodingStandardStyleTest extends TestCase

protected function setUp(): void
{
$outputColorizer = new OutputColorizer();
$this->easyCodingStandardStyle = new EasyCodingStandardStyle(
new OutputPrinter(new OutputColorizer()),
new ProgressBar()
new OutputPrinter($outputColorizer),
new ProgressBar(),
$outputColorizer
);

$this->normalizeTagsReflectionMethod = new ReflectionMethod($this->easyCodingStandardStyle, 'normalizeTags');
Expand Down Expand Up @@ -57,6 +59,8 @@ public static function provideData(): Iterator

yield 'explicit color closing tag is normalized' => ['<fg=red>err</fg=red>', '<fg=red>err</>'];

yield 'grey tag is applied directly' => ['<fg=grey> // 3 files</>', "\033[37m // 3 files\033[0m"];

yield 'plain text is left untouched' => ['no tags here', 'no tags here'];
}
}
Loading