Skip to content

added estimate time to console progress helper #9574

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 12 additions & 5 deletions src/Symfony/Component/Console/Helper/ProgressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProgressHelper extends Helper
{
const FORMAT_QUIET = ' %percent%%';
const FORMAT_NORMAL = ' %current%/%max% [%bar%] %percent%%';
const FORMAT_VERBOSE = ' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed%';
const FORMAT_VERBOSE = ' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed% - Estimated: %estimated%';
Copy link
Member

Choose a reason for hiding this comment

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

I think you have to create a new format

Copy link

Choose a reason for hiding this comment

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

👍 for both: feature and new format.

const FORMAT_QUIET_NOMAX = ' %current%';
const FORMAT_NORMAL_NOMAX = ' %current% [%bar%]';
const FORMAT_VERBOSE_NOMAX = ' %current% [%bar%] Elapsed: %elapsed%';
Expand Down Expand Up @@ -76,6 +76,7 @@ class ProgressHelper extends Helper
'bar',
'percent',
'elapsed',
'estimated',
);

/**
Expand All @@ -91,10 +92,11 @@ class ProgressHelper extends Helper
* @var array
*/
private $widths = array(
'current' => 4,
'max' => 4,
'percent' => 3,
'elapsed' => 6,
'current' => 4,
'max' => 4,
'percent' => 3,
'elapsed' => 6,
'estimated' => 6,
);

/**
Expand Down Expand Up @@ -392,6 +394,11 @@ private function generate($finish = false)
$vars['percent'] = str_pad(floor($percent * 100), $this->widths['percent'], ' ', STR_PAD_LEFT);
}

if (isset($this->formatVars['estimated'])) {
$eta = round((time() - $this->startTime) * ($this->max - $this->current)) / $this->current;
$vars['estimated'] = str_pad($this->humaneTime($eta), $this->widths['estimated'], ' ', STR_PAD_LEFT);
}

return $vars;
}

Expand Down