aboutsummaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2018-06-11 15:02:22 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2018-06-13 11:56:33 +0000
commit1075c22a738140a2655d13242a6b2a1ff2fe6ac4 (patch)
treed3d3cda21c0d634353e2f8be464dbcfc95c71267 /src/app
parent170680d920d28e1c6c1ad0857b00e635b77ef218 (diff)
Do not use colored output on dumb terminals
This prevents the display of escape sequences when using the vanilla emacs compile command, which sets TERM to dumb while isatty returns true. Change-Id: I025b00572af15eb435adfd9287179e05a41c2b0f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/app')
-rw-r--r--src/app/shared/logging/coloredoutput.cpp12
-rw-r--r--src/app/shared/logging/coloredoutput.h1
-rw-r--r--src/app/shared/logging/consolelogger.cpp2
3 files changed, 13 insertions, 2 deletions
diff --git a/src/app/shared/logging/coloredoutput.cpp b/src/app/shared/logging/coloredoutput.cpp
index 33e647d36..0f1bb26da 100644
--- a/src/app/shared/logging/coloredoutput.cpp
+++ b/src/app/shared/logging/coloredoutput.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "coloredoutput.h"
-#include <QtCore/qglobal.h>
+#include <QtCore/qbytearray.h>
#ifdef Q_OS_WIN32
# include <QtCore/qt_windows.h>
#endif
@@ -99,3 +99,13 @@ void fprintfColored(TextColor color, FILE *file, const char *str, ...)
fprintfColored(color, file, str, vl);
va_end(vl);
}
+
+bool terminalSupportsColor()
+{
+#if defined(Q_OS_UNIX)
+ const QByteArray &term = qgetenv("TERM");
+ return !term.isEmpty() && term != "dumb";
+#else
+ return true;
+#endif
+}
diff --git a/src/app/shared/logging/coloredoutput.h b/src/app/shared/logging/coloredoutput.h
index 182d96bbe..a7b145ba5 100644
--- a/src/app/shared/logging/coloredoutput.h
+++ b/src/app/shared/logging/coloredoutput.h
@@ -68,5 +68,6 @@ void printfColored(TextColor color, const char *str, va_list vl);
void printfColored(TextColor color, const char *str, ...);
void fprintfColored(TextColor color, FILE *file, const char *str, va_list vl);
void fprintfColored(TextColor color, FILE *file, const char *str, ...);
+bool terminalSupportsColor();
#endif // QBS_COLOREDOUTPUT_H
diff --git a/src/app/shared/logging/consolelogger.cpp b/src/app/shared/logging/consolelogger.cpp
index ca270759c..7639fb111 100644
--- a/src/app/shared/logging/consolelogger.cpp
+++ b/src/app/shared/logging/consolelogger.cpp
@@ -91,7 +91,7 @@ void ConsoleLogSink::fprintfWrapper(TextColor color, FILE *file, const char *str
{
va_list vl;
va_start(vl, str);
- if (m_coloredOutputEnabled)
+ if (m_coloredOutputEnabled && terminalSupportsColor())
fprintfColored(color, file, str, vl);
else
vfprintf(file, str, vl);