-
Notifications
You must be signed in to change notification settings - Fork 115
Fix progress bar wrapping to new line on Windows #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN'; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
||||||||||||||||||||||
| /** | |
| * CamelCase alias for {@see Shell::is_windows()} to keep the public API consistent. | |
| * | |
| * @return bool | |
| */ | |
| static public function isWindows() { | |
| return self::is_windows(); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| $size -= strlen($msg . $timing); | ||
| if ( $size < 0 ) { | ||
| $size = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WP_CLI_TEST_IS_WINDOWSis cast to boolean with(bool) $test_is_windows, which can misinterpret common string values (e.g.'false'becomestruein PHP). Consider parsing it withfilter_var(..., FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)(and falling back toPHP_OSwhen parsing returnsnull) to avoid incorrect Windows detection when the env var is set.