AuroraRuntime/Source/Console/ConsoleMessage.cpp
Reece e5e36bd887 Large Commit
[*] Fix deadlock in the async subsystem (NoLockShutdown vs Shutdown in exception handler)
[+] Added ProccessMap NT variant
[+] Added ToolHelp image profiling
[*] Improved exception awareness
[*] Delegated SpawnThread to isolated TU, ready for reuse for RunAs and XNU Open - now with horrible evil alloc that could fail
[+] Added header for future api 'UtilRun'
[*] Improve NT core detection
[*] Changed small affinity bitmap to AuUInt64 instead of AuUInt32
[+] Added data structure to hold cpuids/affinity masks
[+] Implemented logger sinks
[+] Implemented logger glue logic
[*] Began migrating older loggers to sink-based default devices
[*] Minor refactors
[*] Improved internal exception discarding, not yet nothrow capable
[*] Minor create directory fix
2022-01-24 18:43:53 +00:00

90 lines
2.1 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"
};
AuString ConsoleMessage::StringifyTime(bool simple) const
{
try
{
std::tm localized;
Aurora::Time::ToCivilTime(time, false).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::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 {};
}
}
AuString ConsoleMessage::ToSimplified() const
{
try
{
return fmt::format("{:<9} {:<7} | {}", StringifyTime(true), GetWrappedTag(), line);
}
catch (...)
{
return {};
}
}
}