From 80293aac9364227afe996416cbf399ad09346ee0 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 17 Mar 2020 10:59:33 +0100 Subject: [PATCH] OutputFormatter: Simplify logic Change-Id: I092cdb351f7530284e915cd4955973b21f2577b5 Reviewed-by: hjk --- src/libs/utils/outputformatter.cpp | 50 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/libs/utils/outputformatter.cpp b/src/libs/utils/outputformatter.cpp index 940b7cee105..3ad865f3ee9 100644 --- a/src/libs/utils/outputformatter.cpp +++ b/src/libs/utils/outputformatter.cpp @@ -204,37 +204,33 @@ void OutputFormatter::appendMessage(const QString &text, OutputFormat format) out.chop(1); } - if (format == ErrorMessageFormat || format == NormalMessageFormat) { + if (format != StdOutFormatSameLine && format != StdErrFormatSameLine) { doAppendMessage(doNewlineEnforcement(out), format); - } else { - const bool sameLine = format == StdOutFormatSameLine || format == StdErrFormatSameLine; - if (sameLine) { - bool enforceNewline = d->enforceNewline; - d->enforceNewline = false; - if (enforceNewline) { - out.prepend('\n'); - } else { - const int newline = out.indexOf('\n'); - plainTextEdit()->moveCursor(QTextCursor::End); - if (newline != -1) { - doAppendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText - out = out.mid(newline); - } - } + return; + } - if (out.isEmpty()) { - d->enforceNewline = true; - } else { - if (out.endsWith('\n')) { - d->enforceNewline = true; - out.chop(1); - } - doAppendMessage(out, format); - } - } else { - doAppendMessage(doNewlineEnforcement(out), format); + const bool enforceNewline = d->enforceNewline; + d->enforceNewline = false; + if (enforceNewline) { + out.prepend('\n'); + } else { + const int newline = out.indexOf('\n'); + plainTextEdit()->moveCursor(QTextCursor::End); + if (newline != -1) { + doAppendMessage(out.left(newline), format);// doesn't enforce new paragraph like appendPlainText + out = out.mid(newline); } } + + if (out.isEmpty()) { + d->enforceNewline = true; + } else { + if (out.endsWith('\n')) { + d->enforceNewline = true; + out.chop(1); + } + doAppendMessage(out, format); + } } QString OutputFormatter::doNewlineEnforcement(const QString &out)