Skip to content

Commit

Permalink
Merge pull request #7620 from weirdan/strip-colors-from-success-message
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 9, 2022
2 parents b06fb93 + 21e6371 commit ba99e77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Psalm/IssueBuffer.php
Expand Up @@ -691,7 +691,7 @@ function (IssueData $d1, IssueData $d2): int {
: $error_count . ' errors'
) . ' found' . "\n";
} else {
self::printSuccessMessage();
self::printSuccessMessage($project_analyzer);
}

$show_info = $project_analyzer->stdout_report_options->show_info;
Expand Down Expand Up @@ -782,8 +782,12 @@ function (IssueData $d1, IssueData $d2): int {
}
}

public static function printSuccessMessage(): void
public static function printSuccessMessage(ProjectAnalyzer $project_analyzer): void
{
if (!$project_analyzer->stdout_report_options) {
throw new UnexpectedValueException('Cannot print success message without stdout report options');
}

// this message will be printed
$message = "No errors found!";

Expand All @@ -808,9 +812,15 @@ public static function printSuccessMessage(): void
// text style, 1 = bold
$style = "1";

echo "\e[{$background};{$style}m{$paddingTop}\e[0m" . "\n";
echo "\e[{$background};{$foreground};{$style}m{$messageWithPadding}\e[0m" . "\n";
echo "\e[{$background};{$style}m{$paddingBottom}\e[0m" . "\n";
if ($project_analyzer->stdout_report_options->use_color) {
echo "\e[{$background};{$style}m{$paddingTop}\e[0m" . "\n";
echo "\e[{$background};{$foreground};{$style}m{$messageWithPadding}\e[0m" . "\n";
echo "\e[{$background};{$style}m{$paddingBottom}\e[0m" . "\n";
} else {
echo "\n";
echo "$messageWithPadding\n";
echo "\n";
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/IssueBufferTest.php
Expand Up @@ -113,8 +113,10 @@ public function testFinishDoesNotCorruptInternalState(): void

public function testPrintSuccessMessageWorks(): void
{
$project_analyzer = $this->createMock(ProjectAnalyzer::class);
$project_analyzer->stdout_report_options = new ReportOptions;
ob_start();
IssueBuffer::printSuccessMessage();
IssueBuffer::printSuccessMessage($project_analyzer);
$output = ob_get_clean();

$this->assertStringContainsString('No errors found!', $output);
Expand Down

0 comments on commit ba99e77

Please sign in to comment.