diff --git a/include/AnsiEscapeCodes.hpp b/include/AnsiEscapeCodes.hpp index ce8220c..465cc61 100644 --- a/include/AnsiEscapeCodes.hpp +++ b/include/AnsiEscapeCodes.hpp @@ -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); diff --git a/include/Color4.hpp b/include/Color4.hpp index 80edc59..34d7f75 100644 --- a/include/Color4.hpp +++ b/include/Color4.hpp @@ -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) { diff --git a/src/Color4.cpp b/src/Color4.cpp index cea22ce..c1e33ad 100644 --- a/src/Color4.cpp +++ b/src/Color4.cpp @@ -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";