Stylistic Refactors
This commit is contained in:
@@ -7,12 +7,13 @@
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
#include "Color4.hpp"
|
||||
|
||||
// Gets set to whatever your terminal emulator is configured for.
|
||||
// This means black can be shown as purple if configured that way.
|
||||
namespace mcolor::ansiColors
|
||||
namespace mcolor
|
||||
{
|
||||
enum class Colors : uint8_t
|
||||
enum class AnsiColor : uint8_t
|
||||
{
|
||||
RESET = 0,
|
||||
BOLD,
|
||||
@@ -54,41 +55,34 @@ namespace mcolor::ansiColors
|
||||
};
|
||||
}
|
||||
|
||||
struct rgbColor
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
namespace mcolor::rgbColors
|
||||
{
|
||||
// Basically default ugly standard UNIX colors for now
|
||||
static const rgbColor BLACK = {0,0,0};
|
||||
static const rgbColor RED = {170, 0, 0};
|
||||
static const rgbColor GREEN = {0, 170, 0};
|
||||
static const rgbColor YELLOW = {170, 170, 0};
|
||||
static const rgbColor BLUE = {0, 0, 170};
|
||||
static const rgbColor MAGENTA = {170, 0, 170};
|
||||
static const rgbColor CYAN = {0, 170, 170};
|
||||
static const rgbColor WHITE = {170, 170, 170};
|
||||
static const rgbColor DEFAULT = {170, 170, 170};
|
||||
static const Color4 BLACK = {0,0,0};
|
||||
static const Color4 RED = {170, 0, 0};
|
||||
static const Color4 GREEN = {0, 170, 0};
|
||||
static const Color4 YELLOW = {170, 170, 0};
|
||||
static const Color4 BLUE = {0, 0, 170};
|
||||
static const Color4 MAGENTA = {170, 0, 170};
|
||||
static const Color4 CYAN = {0, 170, 170};
|
||||
static const Color4 WHITE = {170, 170, 170};
|
||||
static const Color4 DEFAULT = {170, 170, 170};
|
||||
|
||||
static const rgbColor BRIGHT_BLACK = {8,5, 85,};
|
||||
static const rgbColor BRIGHT_RED = {85, 85, 255};
|
||||
static const rgbColor BRIGHT_GREEN = {85, 255, 85};
|
||||
static const rgbColor BRIGHT_YELLOW = {85, 255, 255};
|
||||
static const rgbColor BRIGHT_BLUE = {255, 85, 85};
|
||||
static const rgbColor BRIGHT_MAGENTA = {255, 85, 255};
|
||||
static const rgbColor BRIGHT_CYAN = {255, 255, 85};
|
||||
static const rgbColor BRIGHT_WHITE = {255, 255, 255};
|
||||
static const Color4 BRIGHT_BLACK = {8,5, 85,};
|
||||
static const Color4 BRIGHT_RED = {85, 85, 255};
|
||||
static const Color4 BRIGHT_GREEN = {85, 255, 85};
|
||||
static const Color4 BRIGHT_YELLOW = {85, 255, 255};
|
||||
static const Color4 BRIGHT_BLUE = {255, 85, 85};
|
||||
static const Color4 BRIGHT_MAGENTA = {255, 85, 255};
|
||||
static const Color4 BRIGHT_CYAN = {255, 255, 85};
|
||||
static const Color4 BRIGHT_WHITE = {255, 255, 255};
|
||||
}
|
||||
|
||||
namespace mcolor
|
||||
{
|
||||
std::string toEscapeCode(rgbColor c, bool bg=false);
|
||||
std::string toEscapeCode(Color4 c, bool bg=false);
|
||||
|
||||
std::string toEscapeCode(ansiColors::Colors c);
|
||||
std::string toEscapeCode(AnsiColor c);
|
||||
|
||||
#ifdef WIN32
|
||||
void windowsSaneify();
|
||||
@@ -98,15 +92,15 @@ namespace mcolor
|
||||
|
||||
std::vector<uint8_t> createRGBScale(uint8_t startValue = 200, uint8_t increment = 5);
|
||||
|
||||
std::vector<rgbColor> redScaler(rgbColor c);
|
||||
std::vector<Color4> redScaler(Color4 c);
|
||||
|
||||
std::vector<rgbColor> greenScaler(rgbColor c);
|
||||
std::vector<Color4> greenScaler(Color4 c);
|
||||
|
||||
std::vector<rgbColor> blueScaler(rgbColor c);
|
||||
std::vector<Color4> blueScaler(Color4 c);
|
||||
|
||||
std::vector<rgbColor> RGBColorScale(rgbColor startingColor, std::vector<rgbColor> (*scaler)(rgbColor));
|
||||
std::vector<Color4> RGBColorScale(Color4 startingColor, std::vector<Color4> (*scaler)(Color4));
|
||||
|
||||
void printRGBScale(std::vector<rgbColor> cs);
|
||||
void printRGBScale(std::vector<Color4> cs);
|
||||
|
||||
void printRGBConsoleTest();
|
||||
}
|
||||
|
114
src/mcolor.cpp
114
src/mcolor.cpp
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace mcolor
|
||||
{
|
||||
std::string toEscapeCode(rgbColor c, bool bg)
|
||||
std::string toEscapeCode(Color4 c, bool bg)
|
||||
{
|
||||
if (bg)
|
||||
return std::format("\033[48;2;{};{};{}m", c.r, c.g, c.b);
|
||||
@@ -20,10 +20,10 @@ namespace mcolor
|
||||
return std::format("\033[38;2;{};{};{}m", c.r, c.g, c.b);
|
||||
}
|
||||
|
||||
std::string toEscapeCode(ansiColors::Colors c)
|
||||
std::string toEscapeCode(AnsiColor c)
|
||||
{
|
||||
// Type casting is annoying just saying, but I want to be special about this for some reason
|
||||
return std::format("\033[{}m", static_cast<typename std::underlying_type<ansiColors::Colors>::type>(c));
|
||||
return std::format("\033[{}m", static_cast<typename std::underlying_type<AnsiColor>::type>(c));
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -49,51 +49,51 @@ namespace mcolor
|
||||
|
||||
void printAnsiColorTable()
|
||||
{
|
||||
std::vector<mcolor::ansiColors::Colors> ansifg = {
|
||||
mcolor::ansiColors::Colors::FG_BLACK,
|
||||
mcolor::ansiColors::Colors::FG_RED,
|
||||
mcolor::ansiColors::Colors::FG_GREEN,
|
||||
mcolor::ansiColors::Colors::FG_YELLOW,
|
||||
mcolor::ansiColors::Colors::FG_BLUE,
|
||||
mcolor::ansiColors::Colors::FG_MAGENTA,
|
||||
mcolor::ansiColors::Colors::FG_CYAN,
|
||||
mcolor::ansiColors::Colors::FG_WHITE,
|
||||
std::vector<AnsiColor> ansifg = {
|
||||
AnsiColor::FG_BLACK,
|
||||
AnsiColor::FG_RED,
|
||||
AnsiColor::FG_GREEN,
|
||||
AnsiColor::FG_YELLOW,
|
||||
AnsiColor::FG_BLUE,
|
||||
AnsiColor::FG_MAGENTA,
|
||||
AnsiColor::FG_CYAN,
|
||||
AnsiColor::FG_WHITE,
|
||||
};
|
||||
|
||||
std::vector<mcolor::ansiColors::Colors> ansibg = {
|
||||
mcolor::ansiColors::Colors::BG_BLACK,
|
||||
mcolor::ansiColors::Colors::BG_RED,
|
||||
mcolor::ansiColors::Colors::BG_GREEN,
|
||||
mcolor::ansiColors::Colors::BG_YELLOW,
|
||||
mcolor::ansiColors::Colors::BG_BLUE,
|
||||
mcolor::ansiColors::Colors::BG_MAGENTA,
|
||||
mcolor::ansiColors::Colors::BG_CYAN,
|
||||
mcolor::ansiColors::Colors::BG_WHITE,
|
||||
std::vector<AnsiColor> ansibg = {
|
||||
AnsiColor::BG_BLACK,
|
||||
AnsiColor::BG_RED,
|
||||
AnsiColor::BG_GREEN,
|
||||
AnsiColor::BG_YELLOW,
|
||||
AnsiColor::BG_BLUE,
|
||||
AnsiColor::BG_MAGENTA,
|
||||
AnsiColor::BG_CYAN,
|
||||
AnsiColor::BG_WHITE,
|
||||
};
|
||||
|
||||
std::vector<mcolor::ansiColors::Colors> ansifg_bright = {
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_BLACK,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_RED,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_GREEN,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_YELLOW,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_BLUE,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_MAGENTA,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_CYAN,
|
||||
mcolor::ansiColors::Colors::FG_BRIGHT_WHITE,
|
||||
std::vector<AnsiColor> ansifg_bright = {
|
||||
AnsiColor::FG_BRIGHT_BLACK,
|
||||
AnsiColor::FG_BRIGHT_RED,
|
||||
AnsiColor::FG_BRIGHT_GREEN,
|
||||
AnsiColor::FG_BRIGHT_YELLOW,
|
||||
AnsiColor::FG_BRIGHT_BLUE,
|
||||
AnsiColor::FG_BRIGHT_MAGENTA,
|
||||
AnsiColor::FG_BRIGHT_CYAN,
|
||||
AnsiColor::FG_BRIGHT_WHITE,
|
||||
};
|
||||
|
||||
std::vector<mcolor::ansiColors::Colors> ansibg_bright = {
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_BLACK,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_RED,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_GREEN,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_YELLOW,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_BLUE,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_MAGENTA,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_CYAN,
|
||||
mcolor::ansiColors::Colors::BG_BRIGHT_WHITE,
|
||||
std::vector<AnsiColor> ansibg_bright = {
|
||||
AnsiColor::BG_BRIGHT_BLACK,
|
||||
AnsiColor::BG_BRIGHT_RED,
|
||||
AnsiColor::BG_BRIGHT_GREEN,
|
||||
AnsiColor::BG_BRIGHT_YELLOW,
|
||||
AnsiColor::BG_BRIGHT_BLUE,
|
||||
AnsiColor::BG_BRIGHT_MAGENTA,
|
||||
AnsiColor::BG_BRIGHT_CYAN,
|
||||
AnsiColor::BG_BRIGHT_WHITE,
|
||||
};
|
||||
|
||||
std::vector<mcolor::ansiColors::Colors> all;
|
||||
std::vector<AnsiColor> all;
|
||||
all.insert(all.end(), ansifg.begin(), ansifg.end());
|
||||
all.insert(all.end(), ansibg.begin(), ansibg.end());
|
||||
all.insert(all.end(), ansifg_bright.begin(), ansifg_bright.end());
|
||||
@@ -101,8 +101,8 @@ namespace mcolor
|
||||
|
||||
for (const auto i : all)
|
||||
{
|
||||
auto n = static_cast<typename std::underlying_type<mcolor::ansiColors::Colors>::type>(i);
|
||||
std::cout << mcolor::toEscapeCode(i) << unsigned(n) << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET);
|
||||
auto n = static_cast<typename std::underlying_type<AnsiColor>::type>(i);
|
||||
std::cout << mcolor::toEscapeCode(i) << unsigned(n) << mcolor::toEscapeCode(AnsiColor::RESET);
|
||||
|
||||
if (n == 37 || n == 47 || n == 97 || n == 107)
|
||||
std::cout << std::endl;
|
||||
@@ -119,48 +119,48 @@ namespace mcolor
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> redScaler(rgbColor c)
|
||||
std::vector<Color4> redScaler(Color4 c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
std::vector<Color4> scale;
|
||||
auto nscale = createRGBScale(c.r);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(i, c.g, c.b));
|
||||
scale.push_back(Color4(i, c.g, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> greenScaler(rgbColor c)
|
||||
std::vector<Color4> greenScaler(Color4 c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
std::vector<Color4> scale;
|
||||
auto nscale = createRGBScale(c.g);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, i, c.b));
|
||||
scale.push_back(Color4(c.r, i, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> blueScaler(rgbColor c)
|
||||
std::vector<Color4> blueScaler(Color4 c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
std::vector<Color4> scale;
|
||||
auto nscale = createRGBScale(c.b);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, c.g, i));
|
||||
scale.push_back(Color4(c.r, c.g, i));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> RGBColorScale(rgbColor startingColor, std::vector<rgbColor> (*scaler)(rgbColor))
|
||||
std::vector<Color4> RGBColorScale(Color4 startingColor, std::vector<Color4> (*scaler)(Color4))
|
||||
{
|
||||
return scaler(startingColor);
|
||||
}
|
||||
|
||||
void printRGBScale(std::vector<rgbColor> cs)
|
||||
void printRGBScale(std::vector<Color4> cs)
|
||||
{
|
||||
for (auto i : cs) {
|
||||
std::cout << mcolor::toEscapeCode(i) << mcolor::toEscapeCode(i, true) << ":3" << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET);
|
||||
std::cout << mcolor::toEscapeCode(i) << mcolor::toEscapeCode(i, true) << ":3" << mcolor::toEscapeCode(AnsiColor::RESET);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -179,9 +179,9 @@ namespace mcolor
|
||||
*/
|
||||
void printRGBConsoleTest()
|
||||
{
|
||||
auto redScale = RGBColorScale(rgbColor(), redScaler);
|
||||
auto greenScale = RGBColorScale(rgbColor(), greenScaler);
|
||||
auto blueScale = RGBColorScale(rgbColor(), blueScaler);
|
||||
auto redScale = RGBColorScale(Color4(), redScaler);
|
||||
auto greenScale = RGBColorScale(Color4(), greenScaler);
|
||||
auto blueScale = RGBColorScale(Color4(), blueScaler);
|
||||
|
||||
printRGBScale(redScale);
|
||||
printRGBScale(greenScale);
|
||||
|
Reference in New Issue
Block a user