Basic functional color lib now

This commit is contained in:
2024-07-01 21:55:56 -04:00
parent 792527ff6b
commit 5a5bbd2a53
4 changed files with 73 additions and 50 deletions

View File

@@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.28)
project(mcolor)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
include_directories(include)
add_executable(mcolor main.cpp
include/mcolor.h)
include/mcolor.h
src/mcolor.cpp)

View File

@@ -6,6 +6,7 @@
#include <iostream>
#include <cstdint>
#include <format>
/*
struct ansiColor
@@ -19,54 +20,45 @@ struct ansiColor
namespace mcolor::ansiColors
{
enum class FG_Colors : uint8_t
enum class Colors : uint8_t
{
BLACK = 30,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
DEFAULT = 39,
};
enum class BG_Colors : uint8_t
{
BLACK = 40,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
DEFAULT = 49,
};
enum class FG_Bright_Colors : uint8_t
{
BLACK = 90,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
};
enum class BG_Bright_Colors : uint8_t
{
BLACK = 100,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
RESET = 0,
BOLD,
DIM = 2,
FG_BLACK = 30,
FG_RED,
FG_GREEN,
FG_YELLOW,
FG_BLUE,
FG_MAGENTA,
FG_CYAN,
FG_WHITE,
FG_DEFAULT = 39,
BG_BLACK = 40,
BG_RED,
BG_GREEN,
BG_YELLOW,
BG_BLUE,
BG_MAGENTA,
BG_CYAN,
BG_WHITE,
BG_DEFAULT = 49,
FG_BRIGHT_BLACK = 90,
FG_BRIGHT_RED,
FG_BRIGHT_GREEN,
FG_BRIGHT_YELLOW,
FG_BRIGHT_BLUE,
FG_BRIGHT_MAGENTA,
FG_BRIGHT_CYAN,
FG_BRIGHT_WHITE = 97,
BG_BRIGHT_BLACK = 100,
BG_BRIGHT_RED,
BG_BRIGHT_GREEN,
BG_BRIGHT_YELLOW,
BG_BRIGHT_BLUE,
BG_BRIGHT_MAGENTA,
BG_BRIGHT_CYAN,
BG_BRIGHT_WHITE = 107,
};
}
/*
@@ -115,15 +107,17 @@ namespace mcolor::ansiColorCodes
}
*/
/*
namespace mcolor::ansiControlCodes
{
enum class Text_Manip : uint8_t
enum class Codes : uint8_t
{
RESET,
BOLD,
DIM,
};
}
*/
/*
struct ansiControl
@@ -204,5 +198,7 @@ namespace mcolor::Colors
namespace mcolor
{
std::string toEscapeCode(rgbColor c, bool bg=false);
std::string toEscapeCode(ansiColors::Colors c);
}

View File

@@ -11,5 +11,7 @@ int main()
//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;
return 0;
}

24
src/mcolor.cpp Normal file
View File

@@ -0,0 +1,24 @@
//
// Created by maxine on 7/1/24.
//
#include <mcolor.h>
#include <format>
#include <iostream>
namespace mcolor
{
std::string toEscapeCode(rgbColor c, bool bg)
{
if (bg)
return std::format("\033[48;2;{};{};{}m", c.r, c.g, c.b);
return std::format("\033[38;2;{};{};{}m", c.r, c.g, c.b);
}
std::string toEscapeCode(ansiColors::Colors 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));
}
}