Did some cleanup
This commit is contained in:
130
include/mcolor.h
130
include/mcolor.h
@@ -4,20 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
|
||||
/*
|
||||
struct ansiColor
|
||||
{
|
||||
std::string code;
|
||||
};
|
||||
*/
|
||||
#include <vector>
|
||||
|
||||
// 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
|
||||
{
|
||||
enum class Colors : uint8_t
|
||||
@@ -61,77 +53,6 @@ namespace mcolor::ansiColors
|
||||
BG_BRIGHT_WHITE = 107,
|
||||
};
|
||||
}
|
||||
/*
|
||||
namespace mcolor::ansiColorCodes
|
||||
{
|
||||
|
||||
inline static const ansiColor FG_BLACK = {{"\033[30m"}};
|
||||
inline static const ansiColor FG_RED = {"\033[31m"};
|
||||
inline static const ansiColor FG_GREEN = {"\033[32m"};
|
||||
inline static const ansiColor FG_YELLOW = {"\033[33m"};
|
||||
inline static const ansiColor FG_BLUE = {"\033[34m"};
|
||||
inline static const ansiColor FG_MAGENTA = {"\033[35m"};
|
||||
inline static const ansiColor FG_CYAN = {"\033[36m"};
|
||||
inline static const ansiColor FG_WHITE = {"\033[37m"};
|
||||
inline static const ansiColor FG_DEFAULT = {"\033[39m"};
|
||||
|
||||
|
||||
inline static const ansiColor FG_BRIGHT_BLACK = {"\033[90m"};
|
||||
inline static const ansiColor FG_BRIGHT_RED = {"\033[91m"};
|
||||
inline static const ansiColor FG_BRIGHT_GREEN = {"\033[92m"};
|
||||
inline static const ansiColor FG_BRIGHT_YELLOW = {"\033[93m"};
|
||||
inline static const ansiColor FG_BRIGHT_BLUE = {"\033[94m"};
|
||||
inline static const ansiColor FG_BRIGHT_MAGENTA = {"\033[95m"};
|
||||
inline static const ansiColor FG_BRIGHT_CYAN = {"\033[96m"};
|
||||
inline static const ansiColor FG_BRIGHT_WHITE = {"\033[97m"};
|
||||
|
||||
|
||||
inline static const ansiColor BG_BLACK = {"\033[40m"};
|
||||
inline static const ansiColor BG_RED = {"\033[41m"};
|
||||
inline static const ansiColor BG_GREEN = {"\033[42m"};
|
||||
inline static const ansiColor BG_YELLOW = {"\033[43m"};
|
||||
inline static const ansiColor BG_BLUE = {"\033[44m"};
|
||||
inline static const ansiColor BG_MAGENTA = {"\033[45m"};
|
||||
inline static const ansiColor BG_CYAN = {"\033[46m"};
|
||||
inline static const ansiColor BG_WHITE = {"\033[47m"};
|
||||
inline static const ansiColor BG_DEFAULT = {"\033[49m"};
|
||||
|
||||
inline static const ansiColor BG_BRIGHT_BLACK = {"\033[100m"};
|
||||
inline static const ansiColor BG_BRIGHT_RED = {"\033[101m"};
|
||||
inline static const ansiColor BG_BRIGHT_GREEN = {"\033[102m"};
|
||||
inline static const ansiColor BG_BRIGHT_YELLOW = {"\033[103m"};
|
||||
inline static const ansiColor BG_BRIGHT_BLUE = {"\033[104m"};
|
||||
inline static const ansiColor BG_BRIGHT_MAGENTA = {"\033[105m"};
|
||||
inline static const ansiColor BG_BRIGHT_CYAN = {"\033[106m"};
|
||||
inline static const ansiColor BG_BRIGHT_WHITE = {"\033[107m"};
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
namespace mcolor::ansiControlCodes
|
||||
{
|
||||
enum class Codes : uint8_t
|
||||
{
|
||||
RESET,
|
||||
BOLD,
|
||||
DIM,
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
struct ansiControl
|
||||
{
|
||||
std::string code;
|
||||
};
|
||||
|
||||
namespace mcolor::ansiControlCodes
|
||||
{
|
||||
inline static const ansiControl RESET = {"\033[0m"};
|
||||
inline static const ansiControl BOLD = {"\033[1m"};
|
||||
inline static const ansiControl DIM = {"\033[2m"};
|
||||
}
|
||||
*/
|
||||
|
||||
struct rgbColor
|
||||
{
|
||||
@@ -163,39 +84,6 @@ namespace mcolor::rgbColors
|
||||
static const rgbColor BRIGHT_WHITE = {255, 255, 255};
|
||||
}
|
||||
|
||||
/*
|
||||
struct Color
|
||||
{
|
||||
uint8_t ansi;
|
||||
rgbColor rgb;
|
||||
bool bg = false;
|
||||
};
|
||||
*/
|
||||
|
||||
/*
|
||||
namespace mcolor::Colors
|
||||
{
|
||||
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 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};
|
||||
}
|
||||
*/
|
||||
|
||||
namespace mcolor
|
||||
{
|
||||
std::string toEscapeCode(rgbColor c, bool bg=false);
|
||||
@@ -205,4 +93,20 @@ namespace mcolor
|
||||
#ifdef WIN32
|
||||
void windowsSaneify();
|
||||
#endif
|
||||
|
||||
void printAnsiColorTable();
|
||||
|
||||
std::vector<uint8_t> createRGBScale(uint8_t startValue = 200, uint8_t increment = 5);
|
||||
|
||||
std::vector<rgbColor> redScaler(rgbColor c);
|
||||
|
||||
std::vector<rgbColor> greenScaler(rgbColor c);
|
||||
|
||||
std::vector<rgbColor> blueScaler(rgbColor c);
|
||||
|
||||
std::vector<rgbColor> RGBColorScale(rgbColor startingColor, std::vector<rgbColor> (*scaler)(rgbColor));
|
||||
|
||||
void printRGBScale(std::vector<rgbColor> cs);
|
||||
|
||||
void printRGBConsoleTest();
|
||||
}
|
||||
|
171
main.cpp
171
main.cpp
@@ -3,181 +3,14 @@
|
||||
#include <functional>
|
||||
#include <mcolor.h>
|
||||
|
||||
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<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<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<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<mcolor::ansiColors::Colors> 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());
|
||||
all.insert(all.end(), ansibg_bright.begin(), ansibg_bright.end());
|
||||
|
||||
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);
|
||||
|
||||
if (n == 37 || n == 47 || n == 97 || n == 107)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void printRGBColorTable()
|
||||
{
|
||||
rgbColor red = {100, 0, 0};
|
||||
rgbColor green = {0, 100, 0};
|
||||
rgbColor blue = {0, 0, 100};
|
||||
|
||||
std::cout << mcolor::toEscapeCode(red) << "red" << std::endl;
|
||||
std::cout << mcolor::toEscapeCode(green) << "green" << std::endl;
|
||||
std::cout << mcolor::toEscapeCode(blue) << "blue" << std::endl;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> createRGBScale(uint8_t startValue = 200, uint8_t increment = 5)
|
||||
{
|
||||
std::vector<uint8_t> scale;
|
||||
for (int i = startValue; i < 256; i += increment)
|
||||
{
|
||||
scale.push_back(i);
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> redScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.r);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(i, c.g, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> greenScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.g);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, i, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> blueScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.b);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, c.g, i));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> RGBColorScale(rgbColor startingColor, std::vector<rgbColor> (*scaler)(rgbColor))
|
||||
{
|
||||
return scaler(startingColor);
|
||||
}
|
||||
|
||||
void printRGBScale(std::vector<rgbColor> cs)
|
||||
{
|
||||
for (auto i : cs) {
|
||||
std::cout << mcolor::toEscapeCode(i) << mcolor::toEscapeCode(i, true) << ":3" << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some terminals/consoles can't show all 16 million colors.
|
||||
* This provides a visual test as to whether or not a terminal
|
||||
* can show all 16 million colors.
|
||||
*
|
||||
* If the small change in color scale is visible this means
|
||||
* the terminal is capable of outputting 16 million colors.
|
||||
* If the change is not visible IE most of it looks to be the
|
||||
* same shade then it is not capable.
|
||||
*
|
||||
* QUIRK: The console test fails on Clion's CMD Prompt (Windows). Windows CMD Prompt is fine
|
||||
*/
|
||||
void printRGBConsoleTest()
|
||||
{
|
||||
auto redScale = RGBColorScale(rgbColor(), redScaler);
|
||||
auto greenScale = RGBColorScale(rgbColor(), greenScaler);
|
||||
auto blueScale = RGBColorScale(rgbColor(), blueScaler);
|
||||
|
||||
printRGBScale(redScale);
|
||||
printRGBScale(greenScale);
|
||||
printRGBScale(blueScale);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef WIN32
|
||||
mcolor::windowsSaneify();
|
||||
#endif
|
||||
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
|
||||
//Color c;
|
||||
//c.ansi = mcolor::ansiColorCodes::FG_RED;
|
||||
|
||||
//Color.rgb RED = mcolor::rgbColors::RED;
|
||||
|
||||
//std::cout << c.ansi.code << "Hello, Colors!" << mcolor::ansiControlCodes::RESET.code << std::endl;
|
||||
//std::cout << "ass" << std::endl;
|
||||
std::cout << mcolor::toEscapeCode(mcolor::ansiColors::Colors::FG_RED) << "Hello, Colors!" << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET) << std::endl;
|
||||
std::cout << mcolor::toEscapeCode(mcolor::rgbColors::CYAN) << "Hello, Colors!" << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET) << std::endl;
|
||||
|
||||
printAnsiColorTable();
|
||||
|
||||
//printRGBColorTable();
|
||||
|
||||
printRGBConsoleTest();
|
||||
mcolor::printAnsiColorTable();
|
||||
mcolor::printRGBConsoleTest();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
140
src/mcolor.cpp
140
src/mcolor.cpp
@@ -47,4 +47,144 @@ namespace mcolor
|
||||
}
|
||||
#endif
|
||||
|
||||
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<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<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<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<mcolor::ansiColors::Colors> 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());
|
||||
all.insert(all.end(), ansibg_bright.begin(), ansibg_bright.end());
|
||||
|
||||
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);
|
||||
|
||||
if (n == 37 || n == 47 || n == 97 || n == 107)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> createRGBScale(uint8_t startValue, uint8_t increment)
|
||||
{
|
||||
std::vector<uint8_t> scale;
|
||||
for (int i = startValue; i < 256; i += increment)
|
||||
{
|
||||
scale.push_back(i);
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> redScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.r);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(i, c.g, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> greenScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.g);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, i, c.b));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> blueScaler(rgbColor c)
|
||||
{
|
||||
std::vector<rgbColor> scale;
|
||||
auto nscale = createRGBScale(c.b);
|
||||
for (auto const i : nscale)
|
||||
{
|
||||
scale.push_back(rgbColor(c.r, c.g, i));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
std::vector<rgbColor> RGBColorScale(rgbColor startingColor, std::vector<rgbColor> (*scaler)(rgbColor))
|
||||
{
|
||||
return scaler(startingColor);
|
||||
}
|
||||
|
||||
void printRGBScale(std::vector<rgbColor> cs)
|
||||
{
|
||||
for (auto i : cs) {
|
||||
std::cout << mcolor::toEscapeCode(i) << mcolor::toEscapeCode(i, true) << ":3" << mcolor::toEscapeCode(mcolor::ansiColors::Colors::RESET);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some terminals/consoles can't show all 16 million colors.
|
||||
* This provides a visual test as to whether or not a terminal
|
||||
* can show all 16 million colors.
|
||||
*
|
||||
* If the small change in color scale is visible this means
|
||||
* the terminal is capable of outputting 16 million colors.
|
||||
* If the change is not visible IE most of it looks to be the
|
||||
* same shade then it is not capable.
|
||||
*
|
||||
* QUIRK: The console test fails on Clion's CMD Prompt (Windows). Windows CMD Prompt is fine
|
||||
*/
|
||||
void printRGBConsoleTest()
|
||||
{
|
||||
auto redScale = RGBColorScale(rgbColor(), redScaler);
|
||||
auto greenScale = RGBColorScale(rgbColor(), greenScaler);
|
||||
auto blueScale = RGBColorScale(rgbColor(), blueScaler);
|
||||
|
||||
printRGBScale(redScale);
|
||||
printRGBScale(greenScale);
|
||||
printRGBScale(blueScale);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user