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 lib/cli/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ static public function hide($hidden = true) {
*
* @return bool
*/
static private function is_windows() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
static public function is_windows() {
$test_is_windows = getenv( 'WP_CLI_TEST_IS_WINDOWS' );
if ( false !== $test_is_windows ) {
return (bool) $test_is_windows;
}
Comment on lines +118 to +119
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WP_CLI_TEST_IS_WINDOWS is cast to boolean with (bool) $test_is_windows, which can misinterpret common string values (e.g. 'false' becomes true in PHP). Consider parsing it with filter_var(..., FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) (and falling back to PHP_OS when parsing returns null) to avoid incorrect Windows detection when the env var is set.

Suggested change
return (bool) $test_is_windows;
}
$parsed_test_is_windows = filter_var(
$test_is_windows,
FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE
);
if ( null !== $parsed_test_is_windows ) {
return $parsed_test_is_windows;
}
}

Copilot uses AI. Check for mistakes.
return strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';
}

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making is_windows() public introduces a new public API method that uses snake_case while the other public methods on Shell (e.g. columns(), isPiped()) are camelCase. To keep the public API consistent, consider adding a isWindows() alias (and potentially deprecating is_windows() over time), while retaining the existing method for internal/backwards compatibility.

Suggested change
/**
* CamelCase alias for {@see Shell::is_windows()} to keep the public API consistent.
*
* @return bool
*/
static public function isWindows() {
return self::is_windows();
}

Copilot uses AI. Check for mistakes.
}
Expand Down
4 changes: 4 additions & 0 deletions lib/cli/progress/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function display($finish = false) {
$timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated', 'current', 'total', 'percent'));

$size = Shell::columns();
// On Windows, the cursor wraps to the next line if the output fills the entire width.
if ( Shell::is_windows() ) {
$size -= 1;
}
Comment on lines 84 to +88
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bar::display() now calls Shell::is_windows() on every render, which (with the new implementation) does a getenv() each time. Since progress bars can update very frequently, consider caching the Windows detection result inside Shell::is_windows() (while still allowing the test override env var to take effect) to avoid unnecessary per-tick overhead.

Copilot uses AI. Check for mistakes.
$size -= strlen($msg . $timing);
if ( $size < 0 ) {
$size = 0;
Expand Down
Loading