Skip to content

Commit

Permalink
terminal width auto-detection optimization
Browse files Browse the repository at this point in the history
Removed the assignment of the terminal width auto-detection to a variable in ErrorSuite.php and instead directly used it in the limit calculation. To improve clarity and maintain cleanliness of the code, comments related to terminal width auto-detection fall back have been moved to inside the autoDetectTerminalWidth function in Utils.php.
  • Loading branch information
Denis Smet committed Mar 14, 2024
1 parent 1883bd9 commit 8d19227
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static function isGithubActions(): bool
return self::isDocker() && Env::bool('GITHUB_ACTIONS');
}

/**
* Autodetect the width of the terminal.
*/
public static function autoDetectTerminalWidth(): int
{
static $maxAutoDetected; // Execution optimization
Expand All @@ -126,7 +129,8 @@ public static function autoDetectTerminalWidth(): int
} elseif (self::isDocker()) {
$maxAutoDetected = 140;
} else {
// Fallback value is 80
// 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());
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,8 @@ private static function getTableSize(): array
'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 = Utils::autoDetectTerminalWidth();

$maxWindowWidth = Vars::limit(
$maxAutoDetected,
Utils::autoDetectTerminalWidth(),
$floatingSizes['min'],
$floatingSizes['max'],
) - $floatingSizes['reserve'];
Expand Down

0 comments on commit 8d19227

Please sign in to comment.