mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00

committed by
Brad King

parent
bceb8e2ed2
commit
0a0a0f8a74
4
Help/release/dev/message-color.rst
Normal file
4
Help/release/dev/message-color.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
message-color
|
||||||
|
-------------
|
||||||
|
|
||||||
|
* Messages printed to a terminal now may be colored by message type.
|
@@ -2,7 +2,10 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
|
|
||||||
struct cmMessageMetadata
|
struct cmMessageMetadata
|
||||||
{
|
{
|
||||||
const char* title = nullptr;
|
const char* title = nullptr;
|
||||||
|
int desiredColor = cmsysTerminal_Color_Normal;
|
||||||
};
|
};
|
||||||
|
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
|
|
||||||
MessageType cmMessenger::ConvertMessageType(MessageType t) const
|
MessageType cmMessenger::ConvertMessageType(MessageType t) const
|
||||||
{
|
{
|
||||||
bool warningsAsErrors;
|
bool warningsAsErrors;
|
||||||
@@ -85,6 +87,21 @@ static bool printMessagePreamble(MessageType t, std::ostream& msg)
|
|||||||
return true;
|
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)
|
void printMessageText(std::ostream& msg, std::string const& text)
|
||||||
{
|
{
|
||||||
msg << ":\n";
|
msg << ":\n";
|
||||||
@@ -122,6 +139,7 @@ void displayMessage(MessageType t, std::ostringstream& msg)
|
|||||||
|
|
||||||
// Output the message.
|
// Output the message.
|
||||||
cmMessageMetadata md;
|
cmMessageMetadata md;
|
||||||
|
md.desiredColor = getMessageColor(t);
|
||||||
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
|
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
|
||||||
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
|
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
|
||||||
cmSystemTools::SetErrorOccured();
|
cmSystemTools::SetErrorOccured();
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmProperty.h"
|
#include "cmProperty.h"
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
@@ -37,8 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cmsys/Encoding.hxx"
|
#include "cmsys/Encoding.hxx"
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
struct cmMessageMetadata;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
@@ -150,9 +151,11 @@ std::string cmakemainGetStack(cmake* cm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmakemainMessageCallback(const std::string& m,
|
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)
|
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)
|
||||||
|
Reference in New Issue
Block a user