Reece
d8e000b5c3
[*] Fix up gen1 copypasta [+] ConsoleMessage::ToPersistentString [*] Adjust ConsoleMessage formatting
132 lines
2.9 KiB
C++
132 lines
2.9 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ConsoleMessage.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "ConsoleMessage.hpp"
|
|
|
|
namespace Aurora::Console
|
|
{
|
|
static AuArray<AuString, static_cast<size_t>(EAnsiColor::eCount)> kAnsiCheats
|
|
{
|
|
"\033[0;31m",
|
|
"\033[1;31m",
|
|
"\033[0;32m",
|
|
"\033[1;32m",
|
|
"\033[0;33m",
|
|
"\033[1;33m"
|
|
"\033[0;34m",
|
|
"\033[1;34m",
|
|
"\033[0;35m",
|
|
"\033[1;35m",
|
|
"\033[0;36m",
|
|
"\033[1;36m",
|
|
"\033[0m",
|
|
"\033[0m"
|
|
};
|
|
|
|
static AuString StringifyTimeEx(const ConsoleMessage &msg, bool simple, bool utc)
|
|
{
|
|
try
|
|
{
|
|
std::tm localized;
|
|
|
|
Aurora::Time::ToCivilTime(msg.time, utc).CopyTo(localized);
|
|
|
|
if (simple)
|
|
{
|
|
return fmt::format("{:%H:%M:%S}", localized);
|
|
}
|
|
else
|
|
{
|
|
return fmt::format("{:%Y-%m-%d %H:%M:%S}", localized);
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
|
|
AuString ConsoleMessage::StringifyTime(bool simple) const
|
|
{
|
|
try
|
|
{
|
|
return StringifyTimeEx(*this, simple, false);
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
|
|
AuString ConsoleMessage::StringifyTimeUTC() const
|
|
{
|
|
try
|
|
{
|
|
return StringifyTimeEx(*this, false, true);
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
|
|
AuString ConsoleMessage::GetWrappedTag() const
|
|
{
|
|
return "[" + prefix + "]";
|
|
}
|
|
|
|
AuString ConsoleMessage::ToConsole() const
|
|
{
|
|
try
|
|
{
|
|
return fmt::format("{}[{}] {:<8} | {}{}",
|
|
static_cast<EAnsiColor>(color) <= EAnsiColor::eCount ?
|
|
kAnsiCheats[static_cast<size_t>(color)] :
|
|
"",
|
|
StringifyTime(true),
|
|
GetWrappedTag(),
|
|
line,
|
|
kAnsiCheats[static_cast<size_t>(EAnsiColor::eReset)]);
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
}
|
|
|
|
|
|
AuString ConsoleMessage::ToPersistentString() const
|
|
{
|
|
try
|
|
{
|
|
|
|
return fmt::format("[{}] {:<7} | {}",
|
|
StringifyTimeUTC(),
|
|
GetWrappedTag(),
|
|
line);
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
}
|
|
|
|
AuString ConsoleMessage::ToSimplified() const
|
|
{
|
|
try
|
|
{
|
|
return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), line);
|
|
}
|
|
catch (...)
|
|
{
|
|
return {};
|
|
}
|
|
}
|
|
} |