-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] progress bar fix #16490
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
[Console] progress bar fix #16490
Changes from 1 commit
4edfabc
3a55e6b
77b92da
6a77dbe
066f391
efb2b7d
0dea4e8
846f1be
cc14c56
ac3ad46
c89d24f
cf0e411
eb8a58d
885e4ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,11 @@ | |
|
||
namespace Symfony\Component\Console\Helper; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Exception\LogicException; | ||
use Symfony\Component\Console\Terminal\TerminalDimensionsProvider; | ||
use Symfony\Component\Console\Terminal\TerminalDimensionsProviderInterface; | ||
|
||
/** | ||
* The ProgressBar provides helpers to display progress output. | ||
|
@@ -51,19 +52,24 @@ class ProgressBar | |
private static $formats; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param OutputInterface $output An OutputInterface instance | ||
* @param int $max Maximum steps (0 if unknown) | ||
* @var TerminalDimensionsProviderInterface | ||
*/ | ||
private $terminalDimensionsProvider; | ||
|
||
/** | ||
* @param OutputInterface $output An OutputInterface instance | ||
* @param int $max Maximum steps (0 if unknown) | ||
* @param TerminalDimensionsProviderInterface $terminalDimensionsProvider | ||
*/ | ||
public function __construct(OutputInterface $output, $max = 0) | ||
public function __construct(OutputInterface $output, $max = 0, TerminalDimensionsProviderInterface $terminalDimensionsProvider = null) | ||
{ | ||
if ($output instanceof ConsoleOutputInterface) { | ||
$output = $output->getErrorOutput(); | ||
} | ||
|
||
$this->output = $output; | ||
$this->setMaxSteps($max); | ||
$this->terminalDimensionsProvider = $terminalDimensionsProvider ?: new TerminalDimensionsProvider(); | ||
|
||
if (!$this->output->isDecorated()) { | ||
// disable overwrite when output does not support ANSI codes. | ||
|
@@ -616,31 +622,15 @@ private static function initFormats() | |
private function adjustBarWidthToWindowWidth($line) | ||
{ | ||
$lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line); | ||
$windowWidth = $this->getTerminalWidth(); | ||
$windowWidth = $this->terminalDimensionsProvider->getTerminalWidth(); | ||
if ($lineLength > $windowWidth) { | ||
$barWidthDelta = $lineLength - $windowWidth; | ||
$newBarWidth = $this->barWidth - $barWidthDelta - 20; | ||
$this->setBarWidth($newBarWidth); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new width should be checked for negative values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added check to the It should be always positive number. |
||
|
||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An empty line required before the return... but this method looks strange to me anyway... you should change something or return something but not both... why is return required? |
||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
private function getTerminalWidth() | ||
{ | ||
$dimensions = $this->getTerminalDimensions(); | ||
return $dimensions[0]; | ||
} | ||
|
||
/** | ||
* @return int[] | ||
*/ | ||
private function getTerminalDimensions() | ||
{ | ||
$application = new Application(); | ||
return $application->getTerminalDimensions(); | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
} |
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.
Where that 20 comes from? Seems useless to me.
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.
It shall be calculated as "terminal width - everything except bar width (number, %, memory etc.)"
But first, I need to find way to test this properly.