cpp-terminal icon indicating copy to clipboard operation
cpp-terminal copied to clipboard

Unify Window and Window_24bit

Open certik opened this issue 3 years ago • 1 comments

We have to unify the color type as follows:

diff --git a/cpp-terminal/terminal.cpp b/cpp-terminal/terminal.cpp
index 69a303f..ff076b8 100644
--- a/cpp-terminal/terminal.cpp
+++ b/cpp-terminal/terminal.cpp
@@ -624,6 +624,13 @@ void Term::Window_24bit::clear() {
 }
 
 bool Term::Window_24bit::rgb_equal(rgb& rgb_one, rgb rgb_two) {
+    if (rgb_two.color_type == rgb::type_basic) {
+        std::cout << rgb_two.color_type_union.basic << std::endl;
+    } else {
+        std::cout << rgb_two.color_type_union.rgb.r << std::endl;
+        std::cout << rgb_two.color_type_union.rgb.g << std::endl;
+        std::cout << rgb_two.color_type_union.rgb.b << std::endl;
+    }
     return rgb_one.r == rgb_two.r && rgb_one.b == rgb_two.b &&
            rgb_one.g == rgb_two.g;
 }
diff --git a/cpp-terminal/terminal.h b/cpp-terminal/terminal.h
index a7b384c..c0e4999 100644
--- a/cpp-terminal/terminal.h
+++ b/cpp-terminal/terminal.h
@@ -196,6 +196,33 @@ class Window_24bit {
     std::vector<char32_t> chars;  // the characters in row first order
     struct rgb {
         unsigned int r, g, b;
+        enum ColorType {
+            type_rgb, type_basic
+        } color_type;
+        union ColorTypeUnion {
+            struct {
+                unsigned int r, g, b;
+            } rgb;
+            enum BasicColors {
+                black = 30,
+                red = 31,
+                green = 32,
+                yellow = 33,
+                blue = 34,
+                magenta = 35,
+                cyan = 36,
+                white = 37,
+                reset = 39,
+                gray = 90,
+                bright_red = 91,
+                bright_green = 92,
+                bright_yellow = 93,
+                bright_blue = 94,
+                bright_magenta = 95,
+                bright_cyan = 96,
+                bright_white = 97
+            } basic;
+        } color_type_union;
     };
     std::vector<rgb> m_fg;
     std::vector<rgb> m_bg;

This provides an example how to declare it and how to access it.

certik avatar Nov 12 '21 19:11 certik

We might want to just use the Window_24bit as the base class, and then do some kind of a conversion to 4bit or 8bit at the end.

certik avatar Nov 12 '21 19:11 certik