From d372892ef5c67b092fd38ae7ca1b6a0024c43815 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 29 Jan 2017 21:27:45 +0100 Subject: [PATCH] shellwindow: ensure text is set correctly and only when necessary --- src/gui/widget/shellwindow.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gui/widget/shellwindow.cpp b/src/gui/widget/shellwindow.cpp index f4a1509aa..d8b69068a 100644 --- a/src/gui/widget/shellwindow.cpp +++ b/src/gui/widget/shellwindow.cpp @@ -82,6 +82,16 @@ static int read_line(int fd, struct pollfd *fds, char *b, size_t sz) return i; } +static std::string lines2txt(list &lines) +{ + std::string txt = ""; + for (std::list::const_iterator it = lines.begin(), end = lines.end(); it != end; ++it) { + txt += *it; + txt += '\n'; + } + return txt; +} + void CShellWindow::exec() { std::string cmd; @@ -187,15 +197,8 @@ void CShellWindow::exec() now = time_monotonic_ms(); if (lines.size() > lines_max) lines.pop_front(); - txt = ""; - bool first = true; - for (std::list::const_iterator it = lines.begin(), end = lines.end(); it != end; ++it) { - if (!first) - txt += '\n'; - first = false; - txt += *it; - } if (((lines_read >= lines_max) && (lastPaint + 100 < now)) || (lastPaint + 250 < now)) { + txt = lines2txt(lines); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint(); @@ -211,6 +214,7 @@ void CShellWindow::exec() now = time_monotonic_ms(); if (!ok || (r < 1 && dirty && lastPaint + 250 < now)) { + txt = lines2txt(lines); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint(); @@ -220,6 +224,7 @@ void CShellWindow::exec() } while(ok); if (mode & VERBOSE) { + txt = lines2txt(lines); txt += "\n...ready"; textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); }