Change AnsiEscapeCodes to static const, should compile on MSVC.

This commit is contained in:
2025-06-02 20:03:20 -05:00
parent 36e180b6c0
commit ce624106f9
3 changed files with 10 additions and 3 deletions

View File

@@ -73,11 +73,8 @@ namespace mcolor
#pragma region Cursor Controls
/// Moves cursor to home position {0, 0}.
static const std::string CursorHome = AnsiEscapePrefix + "H";
/// Moves cursor to line Y, column X.
static std::string CursorTo(int line, int column);
/// Moves the cursor up # lines.
static std::string CursorUp(int lines);

View File

@@ -141,6 +141,9 @@ public:
bool operator==(const Color4& rhs) const;
bool operator!=(const Color4& rhs) const;
std::string ToEscapeCode(bool bg = false);
};
inline std::ostream& operator << (std::ostream& os, const Color4& c) {

View File

@@ -355,6 +355,13 @@ bool Color4::operator!=(const Color4& rhs) const
return !(*this == rhs);
}
std::string Color4::ToEscapeCode(bool bg) {
if (bg)
return std::format("\033[48;2;{};{};{}m", r, g, b);
return std::format("\033[38;2;{};{};{}m", r, g, b);
}
static std::string decimal_to_hex(int dec)
{
if (dec < 1) return "00";