Skip to content

Fix progress bar wrapping to new line on Windows#198

Merged
swissspidy merged 2 commits intomainfrom
copilot/fix-progress-bar-line-issue
Mar 11, 2026
Merged

Fix progress bar wrapping to new line on Windows#198
swissspidy merged 2 commits intomainfrom
copilot/fix-progress-bar-line-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

On Windows, the progress bar printed a new line on each update instead of overwriting in place. Windows wraps the cursor when output fills the terminal's full width, leaving no room for the carriage return to stay on the same line.

Changes

  • Shell::is_windows() — promoted from private to public; wired up the pre-existing (but unused) WP_CLI_TEST_IS_WINDOWS env var to make Windows detection testable
  • Bar::display() — subtract 1 from Shell::columns() on Windows only, ensuring the bar never fills the terminal edge and triggers cursor wrap
Original prompt

This section details on the original issue you should resolve

<issue_title>Progress bar goes to new line under windows</issue_title>
<issue_description>The progressbar instead of updating the current row print a new row with the updated values.

To fix this I've found that can be esily fixed by changing into Bar.php line 58 from

$size = Shell::columns();

to

$size = Shell::columns() - 1;

If it was ok as I fix I can also make a pull request for it.

Currently I've not tested it under others OS.</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera @marcovalloni That will probably break all other systems, though. You'd need to add this change conditionally for Windows only. @schlessera @marcovalloni Did https://github.com//pull/131 actually fix this issue? Or is this still happening on Windows?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/cli/progress/Bar.php 0.00% 2 Missing ⚠️
lib/cli/Shell.php 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix progress bar goes to new line under Windows Fix progress bar wrapping to new line on Windows Mar 11, 2026
@swissspidy swissspidy added this to the 0.12.8 milestone Mar 11, 2026
@swissspidy swissspidy marked this pull request as ready for review March 11, 2026 15:21
@swissspidy swissspidy requested a review from a team as a code owner March 11, 2026 15:21
Copilot AI review requested due to automatic review settings March 11, 2026 15:21
@swissspidy swissspidy merged commit 4f0d089 into main Mar 11, 2026
22 of 23 checks passed
@swissspidy swissspidy deleted the copilot/fix-progress-bar-line-issue branch March 11, 2026 15:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Windows terminal cursor-wrap behavior so the progress bar overwrites the same line instead of printing a new line on each update.

Changes:

  • Adjust cli\progress\Bar::display() to keep output under terminal width on Windows by subtracting 1 column.
  • Promote cli\Shell::is_windows() to public and make Windows detection controllable via WP_CLI_TEST_IS_WINDOWS for testing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/cli/progress/Bar.php Avoids filling the full terminal width on Windows to prevent cursor wrap/newline.
lib/cli/Shell.php Exposes Windows detection publicly and adds an env-var override for tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +118 to +119
return (bool) $test_is_windows;
}
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.
Comment on lines 84 to +88
$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;
}
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Progress bar goes to new line under windows

3 participants