AuroraRuntime/Source/Console/ConsoleMessage.cpp

90 lines
2.1 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ConsoleMessage.cpp
Date: 2021-6-12
Author: Reece
***/
2021-09-30 14:57:41 +00:00
#include <Source/RuntimeInternal.hpp>
2021-06-27 21:25:29 +00:00
#include "ConsoleMessage.hpp"
namespace Aurora::Console
{
static AuArray<AuString, static_cast<size_t>(EAnsiColor::eCount)> kAnsiCheats
2021-09-06 10:58:08 +00:00
{
2021-06-27 21:25:29 +00:00
"\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"
};
AuString ConsoleMessage::StringifyTime(bool simple) const
{
try
{
std::tm localized;
2021-06-27 21:25:29 +00:00
Aurora::Time::ToCivilTime(time, false).CopyTo(localized);
2021-06-27 21:25:29 +00:00
if (simple)
{
return fmt::format("{:%H:%M:%S}", localized);
}
else
{
return fmt::format("{:%Y-%m-%d %H:%M:%S}", localized);
}
2021-06-27 21:25:29 +00:00
}
catch (...)
2021-06-27 21:25:29 +00:00
{
return {};
2021-06-27 21:25:29 +00:00
}
}
AuString ConsoleMessage::GetWrappedTag() const
{
return "[" + prefix + "]";
}
AuString ConsoleMessage::ToConsole() const
{
try
{
return fmt::format("{}[{}] {:<7} | {}{}",
static_cast<EAnsiColor>(color) <= EAnsiColor::eCount ?
kAnsiCheats[static_cast<size_t>(color)] :
"",
StringifyTime(),
GetWrappedTag(),
line,
kAnsiCheats[static_cast<size_t>(EAnsiColor::eReset)]);
}
catch (...)
{
return {};
}
2021-06-27 21:25:29 +00:00
}
AuString ConsoleMessage::ToSimplified() const
{
try
{
return fmt::format("{:<9} {:<7} | {}", StringifyTime(true), GetWrappedTag(), line);
}
catch (...)
{
return {};
}
2021-06-27 21:25:29 +00:00
}
}