Skip to content

Commit 9a8ba27

Browse files
Copilotswissspidy
andcommitted
Fix progress bar going to new line on Windows
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 1a3e37c commit 9a8ba27

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/cli/Shell.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ static public function hide($hidden = true) {
112112
*
113113
* @return bool
114114
*/
115-
static private function is_windows() {
116-
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
115+
static public function is_windows() {
116+
$test_is_windows = getenv( 'WP_CLI_TEST_IS_WINDOWS' );
117+
if ( false !== $test_is_windows ) {
118+
return (bool) $test_is_windows;
119+
}
120+
return strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';
117121
}
118122

119123
}

lib/cli/progress/Bar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function display($finish = false) {
8282
$timing = Streams::render($this->_formatTiming, compact('elapsed', 'estimated', 'current', 'total', 'percent'));
8383

8484
$size = Shell::columns();
85+
// On Windows, the cursor wraps to the next line if the output fills the entire width.
86+
if ( Shell::is_windows() ) {
87+
$size -= 1;
88+
}
8589
$size -= strlen($msg . $timing);
8690
if ( $size < 0 ) {
8791
$size = 0;

0 commit comments

Comments
 (0)