Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Console] fixed progress bar jumping #5768

Merged
merged 1 commit into from

5 participants

@tecbot

The progress bar is jumping around on my screen :). This patch will fix this and simplify the previous solution to clear a line.

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
License of the code: MIT
Documentation PR: -

@Seldaek
Collaborator

Should be verified on various platforms I think, because the old code works well for most (we use a similar thing in composer).

@pborreli

@Seldaek i have same issue on Linux when launching the console from anywhere not on top of the screen.

@tecbot on Windows i have a strange character displayed at the begining of the line :

←[K

If i remove

$output->write("\x1B\x5B\x4B"); // clear line

it works but then it fails on Linux

@Seldaek
Collaborator

I think the problem is that the display() method doesn't pass the barWidth and stuff to overwrite(), so it can't do its job properly. In composer what we did is always store the last message length so when you call overwrite it just uses that length to rollback to the beginning of the line, but that's maybe not feasible in the helper.

@tecbot

@Seldaek the composer progress on the console jumps also around on my machine (from left to right, from right to the middle and so on :D). (Debian Squeeze)

Hm maybe we can use a another solution if the env is windows? This solution works perfect on linux.

@pborreli

the goal of my comment was : let's try to find a way that works on all systems :)

@fabpot
Owner

Any news on this issue?

@robqu

a smart solution for this problem is not possible because the windows console does not support the ANSI escape sequences: http://en.wikipedia.org/wiki/ANSI_escape_code

my suggestion is:

$output->write("\x0D"); // carriage return
$output->write(str_repeat(' ', strlen($lastMessages))); //clear the line with the length of the last message
$output->write("\x0D"); // carriage return

this works in windows and unix but you need the last written message

@fabpot
Owner

@robqu Can you work on a PR that implements your suggestion?

@robqu

Done.

@fabpot fabpot merged commit 6a0ee27 into from
@fabpot
Owner

Closing in favor of #6266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. @tecbot
This page is out of date. Refresh to see the latest.
View
15 src/Symfony/Component/Console/Helper/ProgressHelper.php
@@ -380,21 +380,12 @@ private function humaneTime($secs)
*
* @param OutputInterface $output An Output instance
* @param string|array $messages The message as an array of lines or a single string
- * @param Boolean $newline Whether to add a newline or not
- * @param integer $size The size of line
*/
- private function overwrite(OutputInterface $output, $messages, $newline = false, $size = 80)
+ private function overwrite(OutputInterface $output, $messages)
{
- $output->write(str_repeat("\x08", $size));
+ $output->write("\x0D"); // carriage return
+ $output->write("\x1B\x5B\x4B"); // clear line
$output->write($messages);
- $output->write(str_repeat(' ', $size - strlen($messages)));
-
- // clean up the end line
- $output->write(str_repeat("\x08", $size - strlen($messages)));
-
- if ($newline) {
- $output->writeln('');
- }
}
/**
View
2  src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php
@@ -82,6 +82,6 @@ protected function getOutputStream()
protected function generateOutput($expected)
{
- return str_repeat("\x08", 80).$expected.str_repeat(' ', 80 - strlen($expected)).str_repeat("\x08", 80 - strlen($expected));
+ return "\x0D\x1B\x5B\x4B".$expected;
}
}
Something went wrong with that request. Please try again.