Colors in terminal is now cross-platform
This commit is contained in:
35
Common/IO.h
35
Common/IO.h
@@ -78,13 +78,42 @@ namespace LXC::Internal
|
|||||||
|
|
||||||
#elif defined(__unix__)
|
#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)
|
inline void WriteImpl(std::ostream& os, Args&&... args)
|
||||||
{
|
{
|
||||||
|
if constexpr (col != Util::Color::DEFAULT)
|
||||||
|
os << GetAnsiCode(col);
|
||||||
|
|
||||||
(os << ... << std::forward<Args>(args));
|
(os << ... << std::forward<Args>(args));
|
||||||
|
|
||||||
if constexpr (newLine)
|
if constexpr (newLine)
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
|
if constexpr (col != Util::Color::DEFAULT)
|
||||||
|
os << GetAnsiCode(Util::Color::DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user