Skip to content

[Console] ProgressBar adds extra whitespace to clear the line vs \033[2K escape code #16957

Closed
@neon64

Description

@neon64

I noticed that the ProgressBar class uses the following to make sure the previous status is completely overwritten. However for me on a Mac with iTerm2/zsh it doesn't seem to work.

if (null !== $this->lastMessagesLength) {
    foreach ($lines as $i => $line) {
        if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $line)) {
            $lines[$i] = str_pad($line, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
        }
    }
}

However if I use the \033[2K ANSI escape sequence then it seems to work better:

if ($this->overwrite) {
    // move back to the beginning of the progress bar before redrawing it
    $this->output->write("\x0D"); // move back
    $this->output->write("\033[2K"); // clear
} elseif ($this->step > 0) {
    // move to new line
    $this->output->writeln('');
}

if ($this->formatLineCount) {
    $this->output->write(str_repeat("\033[1A\033[2K", $this->formatLineCount)); // move up and clear
}

Is there a reason why Symfony doesn't use the escape code. I thought perhaps it doesn't work on Windows, but then neither should \x0D or all the other escape sequences Symfony uses.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions