Colors in terminal is now cross-platform

This commit is contained in:
2025-07-21 20:21:08 +01:00
parent cde435ba55
commit 759a9e3a88

View File

@@ -78,13 +78,42 @@ namespace LXC::Internal
#elif defined(__unix__)
template<Util::Color clo, bool newLine, typename... Args>
static const char* GetAnsiCode(Util::Color color)
{
switch (color)
{
case Util::Color::BLACK: return "\x1b[30m";
case Util::Color::BLUE: return "\x1b[34m";
case Util::Color::GREEN: return "\x1b[32m";
case Util::Color::AQUA: return "\x1b[36m";
case Util::Color::RED: return "\x1b[31m";
case Util::Color::PURPLE: return "\x1b[35m";
case Util::Color::YELLOW: return "\x1b[33m";
case Util::Color::LIGHT_GRAY: return "\x1b[0m";
case Util::Color::LIGHT_BLUE: return "\x1b[94m";
case Util::Color::LIGHT_GREEN: return "\x1b[92m";
case Util::Color::LIGHT_AQUA: return "\x1b[96m";
case Util::Color::LIGHT_RED: return "\x1b[91m";
case Util::Color::LIGHT_PURPLE: return "\x1b[95m";
case Util::Color::LIGHT_YELLOW: return "\x1b[93m";
case Util::Color::WHITE: return "\x1b[97m";
default: return "\x1b[0m";
}
}
template<Util::Color col, bool newLine, typename... Args>
inline void WriteImpl(std::ostream& os, Args&&... args)
{
if constexpr (col != Util::Color::DEFAULT)
os << GetAnsiCode(col);
(os << ... << std::forward<Args>(args));
if constexpr (newLine)
os << std::endl;
if constexpr (newLine)
os << std::endl;
if constexpr (col != Util::Color::DEFAULT)
os << GetAnsiCode(Util::Color::DEFAULT);
}
#endif