Skip to content

Commit

Permalink
Refine terminal width determination and add Docker environment check
Browse files Browse the repository at this point in the history
The terminal width determination code in ErrorSuite.php has been updated to consider Docker environments. A new method, autoDetectTerminalWidth(), has been added for this functionality. Furthermore, in Utils.php, the isGithubActions() now includes a Docker environment check ensuring the functionality considers both contexts. This enhances reusability and precision in terminal width estimation.
  • Loading branch information
Denis Smet committed Mar 14, 2024
1 parent c8d292e commit db657c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public static function isDocker(): bool

public static function isGithubActions(): bool
{
return Env::bool('GITHUB_ACTIONS');
return self::isDocker() && Env::bool('GITHUB_ACTIONS');
}
}
23 changes: 17 additions & 6 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,14 @@ private static function getTableSize(): array
'line' => 10,
'column' => 20,
'rule' => 20,
'min' => 90,
'min' => 120,
'max' => 150,
'reserve' => 5, // So that the table does not rest on the very edge of the terminal. Just in case.
'reserve' => 3, // So that the table does not rest on the very edge of the terminal. Just in case.
];

// Fallback to 80 if the terminal width cannot be determined.
// env.COLUMNS_TEST usually not defined, so we use it only for testing purposes.
$maxAutoDetected = Env::int('COLUMNS_TEST', Cli::getNumberOfColumns());
if (Utils::isDocker() && Utils::isGithubActions()) {
$maxAutoDetected = 150; // GitHub Actions has a wide terminal
}
$maxAutoDetected = self::autoDetectTerminalWidth();

$maxWindowWidth = Vars::limit(
$maxAutoDetected,
Expand All @@ -225,4 +222,18 @@ private static function getTableSize(): array

return $floatingSizes;
}

private static function autoDetectTerminalWidth(): int
{
$maxAutoDetected = Env::int('COLUMNS_TEST', Cli::getNumberOfColumns());
if (Utils::isDocker()) {
$maxAutoDetected = 120;
}

if (Utils::isGithubActions()) {
$maxAutoDetected = 200; // GitHub Actions has a wide terminal
}

return $maxAutoDetected;
}
}

0 comments on commit db657c2

Please sign in to comment.