Add truecolor support

This commit is contained in:
Bob Polis 2024-01-17 18:09:25 +01:00
parent e4c04ae996
commit 176d5bf81d
2 changed files with 33 additions and 1 deletions

View File

@ -2,7 +2,6 @@
#include <unistd.h> #include <unistd.h>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <string>
using namespace sc::io; using namespace sc::io;
@ -244,3 +243,17 @@ sc::io::trgb::operator rgbf() {
}; };
return result; 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;
}

View File

@ -92,6 +92,25 @@ namespace sc {
const trgb magenta {1.0, 0.0, 1.0}; const trgb magenta {1.0, 0.0, 1.0};
const trgb cyan {0.0, 1.0, 1.0}; const trgb cyan {0.0, 1.0, 1.0};
const trgb white {1.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);
} }
} }