mirror of
https://github.com/gabime/spdlog.git
synced 2025-05-06 06:23:52 +00:00
bugfix in color detection and astyle
This commit is contained in:
parent
eb92cc35df
commit
1d6842f0f9
@ -365,14 +365,19 @@ inline std::string filename_to_str(const filename_t& filename)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline std::string errno_to_string(char [256], char* res) {
|
inline std::string errno_to_string(char [256], char* res)
|
||||||
|
{
|
||||||
return std::string(res);
|
return std::string(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string errno_to_string(char buf[256], int res) {
|
inline std::string errno_to_string(char buf[256], int res)
|
||||||
if (res == 0) {
|
{
|
||||||
|
if (res == 0)
|
||||||
|
{
|
||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,20 +427,24 @@ bool is_color_terminal()
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
static constexpr const char* Terms[] = {
|
static constexpr const char* Terms[] =
|
||||||
|
{
|
||||||
"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm",
|
"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm",
|
||||||
"linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"
|
"linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *env_p = std::getenv("TERM");
|
const char *env_p = std::getenv("TERM");
|
||||||
if (env_p == nullptr) {
|
if (env_p == nullptr)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const bool result = std::any_of(
|
static const bool result = std::any_of(
|
||||||
std::begin(Terms), std::end(Terms), [&](const char* term) {
|
std::begin(Terms), std::end(Terms), [&](const char* term)
|
||||||
|
{
|
||||||
return std::strstr(env_p, term) != nullptr;
|
return std::strstr(env_p, term) != nullptr;
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ namespace spdlog
|
|||||||
{
|
{
|
||||||
// Wrap the originally formatted message in color codes.
|
// Wrap the originally formatted message in color codes.
|
||||||
// If color is not supported in the terminal, log as is instead.
|
// If color is not supported in the terminal, log as is instead.
|
||||||
if (is_color_terminal_) {
|
if (is_color_terminal_)
|
||||||
|
{
|
||||||
const std::string& prefix = colors_[msg.level];
|
const std::string& prefix = colors_[msg.level];
|
||||||
const std::string& s = msg.formatted.str();
|
const std::string& s = msg.formatted.str();
|
||||||
const std::string& suffix = reset;
|
const std::string& suffix = reset;
|
||||||
@ -100,7 +101,8 @@ namespace spdlog
|
|||||||
m.formatted << prefix << s << suffix;
|
m.formatted << prefix << s << suffix;
|
||||||
sink_->log(m);
|
sink_->log(m);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
sink_->log(msg);
|
sink_->log(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user