summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/release/dev/message-color.rst4
-rw-r--r--Source/cmMessageMetadata.h3
-rw-r--r--Source/cmMessenger.cxx18
-rw-r--r--Source/cmakemain.cxx11
4 files changed, 32 insertions, 4 deletions
diff --git a/Help/release/dev/message-color.rst b/Help/release/dev/message-color.rst
new file mode 100644
index 0000000..4acf15e
--- /dev/null
+++ b/Help/release/dev/message-color.rst
@@ -0,0 +1,4 @@
+message-color
+-------------
+
+* Messages printed to a terminal now may be colored by message type.
diff --git a/Source/cmMessageMetadata.h b/Source/cmMessageMetadata.h
index 5688dc5..7b56fae 100644
--- a/Source/cmMessageMetadata.h
+++ b/Source/cmMessageMetadata.h
@@ -2,7 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
+#include "cmsys/Terminal.h"
+
struct cmMessageMetadata
{
const char* title = nullptr;
+ int desiredColor = cmsysTerminal_Color_Normal;
};
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx
index 4c0faa9..1cb638a 100644
--- a/Source/cmMessenger.cxx
+++ b/Source/cmMessenger.cxx
@@ -13,6 +13,8 @@
#include <sstream>
+#include "cmsys/Terminal.h"
+
MessageType cmMessenger::ConvertMessageType(MessageType t) const
{
bool warningsAsErrors;
@@ -85,6 +87,21 @@ static bool printMessagePreamble(MessageType t, std::ostream& msg)
return true;
}
+static int getMessageColor(MessageType t)
+{
+ switch (t) {
+ case MessageType::INTERNAL_ERROR:
+ case MessageType::FATAL_ERROR:
+ case MessageType::AUTHOR_ERROR:
+ return cmsysTerminal_Color_ForegroundRed;
+ case MessageType::AUTHOR_WARNING:
+ case MessageType::WARNING:
+ return cmsysTerminal_Color_ForegroundYellow;
+ default:
+ return cmsysTerminal_Color_Normal;
+ }
+}
+
void printMessageText(std::ostream& msg, std::string const& text)
{
msg << ":\n";
@@ -122,6 +139,7 @@ void displayMessage(MessageType t, std::ostringstream& msg)
// Output the message.
cmMessageMetadata md;
+ md.desiredColor = getMessageColor(t);
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
cmSystemTools::SetErrorOccured();
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 60ac0ca..93eb415 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -6,6 +6,7 @@
#include <algorithm>
#include <cassert>
#include <climits>
+#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -23,6 +24,7 @@
#include "cmDocumentationEntry.h" // IWYU pragma: keep
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageMetadata.h"
#include "cmProperty.h"
#include "cmState.h"
#include "cmStateTypes.h"
@@ -37,8 +39,7 @@
#endif
#include "cmsys/Encoding.hxx"
-
-struct cmMessageMetadata;
+#include "cmsys/Terminal.h"
namespace {
#ifndef CMAKE_BOOTSTRAP
@@ -150,9 +151,11 @@ std::string cmakemainGetStack(cmake* cm)
}
void cmakemainMessageCallback(const std::string& m,
- const cmMessageMetadata& /* unused */, cmake* cm)
+ const cmMessageMetadata& md, cmake* cm)
{
- std::cerr << m << cmakemainGetStack(cm) << std::endl;
+ cmsysTerminal_cfprintf(md.desiredColor, stderr, "%s", m.c_str());
+ fflush(stderr); // stderr is buffered in some cases.
+ std::cerr << cmakemainGetStack(cm) << "\n";
}
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)