AuroraRuntime/Source/Console/ConsoleMessage.cpp
2021-06-27 22:25:29 +01:00

60 lines
1.5 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 <RuntimeInternal.hpp>
#include "ConsoleMessage.hpp"
namespace Aurora::Console
{
static std::array<std::string, static_cast<size_t>(EAnsiColor::eCount)> AnsiCheats{
"\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
{
tm localized;
localized = Aurora::Time::ToCivilTime(time, false);
if (simple)
{
return fmt::format("{:%H:%M:%S}", localized);
}
else
{
return fmt::format("{:%Y-%m-%d %H:%M:%S}", localized);
}
}
AuString ConsoleMessage::GetWrappedTag() const
{
return "[" + prefix + "]";
}
AuString ConsoleMessage::ToConsole() const
{
return fmt::format("{}[{}] {:<7} | {}{}", AnsiCheats[static_cast<size_t>(color)], StringifyTime(), GetWrappedTag(), line, AnsiCheats[static_cast<size_t>(EAnsiColor::eReset)]);
}
AuString ConsoleMessage::ToSimplified() const
{
return fmt::format("{:<9} {:<7} | {}", StringifyTime(true), GetWrappedTag(), line);
}
}