From 176d5bf81d896bbd6539e2b9d92069d2181ce0f1 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 17 Jan 2024 18:09:25 +0100 Subject: [PATCH] Add truecolor support --- src/iomanip.cpp | 15 ++++++++++++++- src/iomanip.hpp | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/iomanip.cpp b/src/iomanip.cpp index b51e97e..26e8358 100644 --- a/src/iomanip.cpp +++ b/src/iomanip.cpp @@ -2,7 +2,6 @@ #include #include #include -#include using namespace sc::io; @@ -244,3 +243,17 @@ sc::io::trgb::operator rgbf() { }; return result; } + +sc::io::truecolorf::truecolorf(int r, int g, int b) : _r {r}, _g {g}, _b {b} {} + +sc::io::truecolorb::truecolorb(int r, int g, int b) : _r {r}, _g {g}, _b {b} {} + +std::ostream& sc::io::operator<<(std::ostream& out, const truecolorf& obj) { + out << "\x1b[38;2;" << obj._r << ';' << obj._g << ';' << obj._b << 'm'; + return out; +} + +std::ostream& sc::io::operator<<(std::ostream& out, const truecolorb& obj) { + out << "\x1b[48;2;" << obj._r << ';' << obj._g << ';' << obj._b << 'm'; + return out; +} diff --git a/src/iomanip.hpp b/src/iomanip.hpp index 792bbac..7ed7569 100644 --- a/src/iomanip.hpp +++ b/src/iomanip.hpp @@ -92,6 +92,25 @@ namespace sc { const trgb magenta {1.0, 0.0, 1.0}; const trgb cyan {0.0, 1.0, 1.0}; const trgb white {1.0, 1.0, 1.0}; + + struct truecolorf { + int _r; // 0 .. 255 + int _g; // 0 .. 255 + int _b; // 0 .. 255 + + truecolorf(int r, int g, int b); + }; + + struct truecolorb { + int _r; // 0 .. 255 + int _g; // 0 .. 255 + int _b; // 0 .. 255 + + truecolorb(int r, int g, int b); + }; + + std::ostream& operator<<(std::ostream& out, const truecolorf& obj); + std::ostream& operator<<(std::ostream& out, const truecolorb& obj); } }