From b7fb60494d881a90e78674fced037a97626f458f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 11 Nov 2012 15:05:27 +0100 Subject: [PATCH] Add handling for backspace chars in BufferIO --- src/Composer/IO/BufferIO.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Composer/IO/BufferIO.php b/src/Composer/IO/BufferIO.php index 3ab51d34b..8e1818a97 100644 --- a/src/Composer/IO/BufferIO.php +++ b/src/Composer/IO/BufferIO.php @@ -40,6 +40,19 @@ class BufferIO extends ConsoleIO { fseek($this->output->getStream(), 0); - return stream_get_contents($this->output->getStream()); + $output = stream_get_contents($this->output->getStream()); + + $output = preg_replace_callback("{(?<=^|\n|\x08)(.+?)(\x08+)}", function ($matches) { + $pre = strip_tags($matches[1]); + + if (strlen($pre) === strlen($matches[2])) { + return ''; + } + + // TODO reverse parse the string, skipping span tags and \033\[([0-9;]+)m(.*?)\033\[0m style blobs + return rtrim($matches[1])."\n"; + }, $output); + + return $output; } }