Basic functional color lib now
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.28)
|
cmake_minimum_required(VERSION 3.28)
|
||||||
project(mcolor)
|
project(mcolor)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
add_executable(mcolor main.cpp
|
add_executable(mcolor main.cpp
|
||||||
include/mcolor.h)
|
include/mcolor.h
|
||||||
|
src/mcolor.cpp)
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct ansiColor
|
struct ansiColor
|
||||||
@@ -19,54 +20,45 @@ struct ansiColor
|
|||||||
|
|
||||||
namespace mcolor::ansiColors
|
namespace mcolor::ansiColors
|
||||||
{
|
{
|
||||||
enum class FG_Colors : uint8_t
|
enum class Colors : uint8_t
|
||||||
{
|
{
|
||||||
BLACK = 30,
|
RESET = 0,
|
||||||
RED,
|
BOLD,
|
||||||
GREEN,
|
DIM = 2,
|
||||||
YELLOW,
|
FG_BLACK = 30,
|
||||||
BLUE,
|
FG_RED,
|
||||||
MAGENTA,
|
FG_GREEN,
|
||||||
CYAN,
|
FG_YELLOW,
|
||||||
WHITE,
|
FG_BLUE,
|
||||||
DEFAULT = 39,
|
FG_MAGENTA,
|
||||||
};
|
FG_CYAN,
|
||||||
|
FG_WHITE,
|
||||||
enum class BG_Colors : uint8_t
|
FG_DEFAULT = 39,
|
||||||
{
|
BG_BLACK = 40,
|
||||||
BLACK = 40,
|
BG_RED,
|
||||||
RED,
|
BG_GREEN,
|
||||||
GREEN,
|
BG_YELLOW,
|
||||||
YELLOW,
|
BG_BLUE,
|
||||||
BLUE,
|
BG_MAGENTA,
|
||||||
MAGENTA,
|
BG_CYAN,
|
||||||
CYAN,
|
BG_WHITE,
|
||||||
WHITE,
|
BG_DEFAULT = 49,
|
||||||
DEFAULT = 49,
|
FG_BRIGHT_BLACK = 90,
|
||||||
};
|
FG_BRIGHT_RED,
|
||||||
|
FG_BRIGHT_GREEN,
|
||||||
enum class FG_Bright_Colors : uint8_t
|
FG_BRIGHT_YELLOW,
|
||||||
{
|
FG_BRIGHT_BLUE,
|
||||||
BLACK = 90,
|
FG_BRIGHT_MAGENTA,
|
||||||
RED,
|
FG_BRIGHT_CYAN,
|
||||||
GREEN,
|
FG_BRIGHT_WHITE = 97,
|
||||||
YELLOW,
|
BG_BRIGHT_BLACK = 100,
|
||||||
BLUE,
|
BG_BRIGHT_RED,
|
||||||
MAGENTA,
|
BG_BRIGHT_GREEN,
|
||||||
CYAN,
|
BG_BRIGHT_YELLOW,
|
||||||
WHITE,
|
BG_BRIGHT_BLUE,
|
||||||
};
|
BG_BRIGHT_MAGENTA,
|
||||||
|
BG_BRIGHT_CYAN,
|
||||||
enum class BG_Bright_Colors : uint8_t
|
BG_BRIGHT_WHITE = 107,
|
||||||
{
|
|
||||||
BLACK = 100,
|
|
||||||
RED,
|
|
||||||
GREEN,
|
|
||||||
YELLOW,
|
|
||||||
BLUE,
|
|
||||||
MAGENTA,
|
|
||||||
CYAN,
|
|
||||||
WHITE,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -115,15 +107,17 @@ namespace mcolor::ansiColorCodes
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
namespace mcolor::ansiControlCodes
|
namespace mcolor::ansiControlCodes
|
||||||
{
|
{
|
||||||
enum class Text_Manip : uint8_t
|
enum class Codes : uint8_t
|
||||||
{
|
{
|
||||||
RESET,
|
RESET,
|
||||||
BOLD,
|
BOLD,
|
||||||
DIM,
|
DIM,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct ansiControl
|
struct ansiControl
|
||||||
@@ -204,5 +198,7 @@ namespace mcolor::Colors
|
|||||||
|
|
||||||
namespace mcolor
|
namespace mcolor
|
||||||
{
|
{
|
||||||
|
std::string toEscapeCode(rgbColor c, bool bg=false);
|
||||||
|
|
||||||
|
std::string toEscapeCode(ansiColors::Colors c);
|
||||||
}
|
}
|
||||||
|
2
main.cpp
2
main.cpp
@@ -11,5 +11,7 @@ int main()
|
|||||||
//Color.rgb RED = mcolor::rgbColors::RED;
|
//Color.rgb RED = mcolor::rgbColors::RED;
|
||||||
|
|
||||||
//std::cout << c.ansi.code << "Hello, Colors!" << mcolor::ansiControlCodes::RESET.code << std::endl;
|
//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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
24
src/mcolor.cpp
Normal file
24
src/mcolor.cpp
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user