Browse Source

Add comment as a color to log

master
Riyyi 3 years ago
parent
commit
61b061d55a
  1. 9
      inferno/src/inferno/log.cpp
  2. 9
      inferno/src/inferno/log.h

9
inferno/src/inferno/log.cpp

@ -126,7 +126,7 @@ namespace Inferno {
const LogStream& operator<<(const LogStream& stream, Log value) const LogStream& operator<<(const LogStream& stream, Log value)
{ {
switch (value) { switch (value) {
case Log::Log: case Log::None:
return stream << "Log"; return stream << "Log";
case Log::Info: case Log::Info:
return stream << "Info"; return stream << "Info";
@ -136,6 +136,8 @@ namespace Inferno {
return stream << "Danger"; return stream << "Danger";
case Log::Success: case Log::Success:
return stream << "Success"; return stream << "Success";
case Log::Comment:
return stream << "Comment";
default: default:
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
return stream; return stream;
@ -218,7 +220,7 @@ namespace Inferno {
DebugLogStream::~DebugLogStream() DebugLogStream::~DebugLogStream()
{ {
if (m_type != Log::Log) { if (m_type != Log::None) {
write("\033[0m", 4); write("\033[0m", 4);
} }
@ -243,6 +245,9 @@ namespace Inferno {
else if (m_type == Log::Success) { else if (m_type == Log::Success) {
color = "\x1B[32m"; color = "\x1B[32m";
} }
else if (m_type == Log::Comment) {
color = "\x1B[37m";
}
if (color[0] != '\0') { if (color[0] != '\0') {
write(color, 5); write(color, 5);

9
inferno/src/inferno/log.h

@ -8,11 +8,12 @@
namespace Inferno { namespace Inferno {
enum class Log { enum class Log {
Log, None,
Info, Info,
Warn, Warn,
Danger, Danger,
Success, Success,
Comment,
}; };
// ---------------------------------------- // ----------------------------------------
@ -31,9 +32,9 @@ namespace Inferno {
class DebugLogStream final : public LogStream{ class DebugLogStream final : public LogStream{
public: public:
DebugLogStream(): DebugLogStream():
m_newline(true), m_type(Log::Log) {} m_newline(true), m_type(Log::None) {}
DebugLogStream(bool newline): DebugLogStream(bool newline):
m_newline(newline), m_type(Log::Log) {} m_newline(newline), m_type(Log::None) {}
DebugLogStream(Log type): DebugLogStream(Log type):
m_newline(true), m_type(type) { color(); } m_newline(true), m_type(type) { color(); }
DebugLogStream(Log type, bool newline): DebugLogStream(Log type, bool newline):
@ -102,7 +103,7 @@ namespace Inferno {
template<typename T, typename... P> template<typename T, typename... P>
void dbgln(const char* format, T value, const P&... parameters) void dbgln(const char* format, T value, const P&... parameters)
{ {
dbgln(Log::Log, true, format, value, parameters...); dbgln(Log::None, true, format, value, parameters...);
} }
template<typename T, typename... P> template<typename T, typename... P>

Loading…
Cancel
Save