Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip colours from success message #7620

Merged
merged 1 commit into from Feb 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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