فهرست منبع

Updated renderFunction to use append.

This is the much better way to build the
render.
Steve Thielemann 3 سال پیش
والد
کامیت
5f0547bcff
3فایلهای تغییر یافته به همراه12 افزوده شده و 219 حذف شده
  1. 4 134
      door.cpp
  2. 0 9
      door.h
  3. 8 76
      panel.cpp

+ 4 - 134
door.cpp

@@ -1204,146 +1204,16 @@ const char RestoreCursor[] = "\x1b[u";
 renderFunction rBlueYellow = [](const std::string &txt) -> Render {
   Render r(txt);
 
-  ColorOutput co;
-
-  bool uc = true;
   ANSIColor blue(COLOR::BLUE, ATTR::BOLD);
   ANSIColor cyan(COLOR::YELLOW, ATTR::BOLD);
 
-  co.pos = 0;
-  co.len = 0;
-  co.c = blue;
-  // d << blue;
-
-  int tpos = 0;
   for (char const &c : txt) {
-    if (uc) {
-      if (!isupper(c)) {
-        // possible color change
-        if (co.len != 0) {
-          r.outputs.push_back(co);
-          co.reset();
-          co.pos = tpos;
-        }
-
-        co.c = cyan;
-        // d << cyan;
-        uc = false;
-      }
-    } else {
-      if (isupper(c)) {
-        if (co.len != 0) {
-          r.outputs.push_back(co);
-          co.reset();
-          co.pos = tpos;
-        }
-        co.c = blue;
-
-        // d << blue;
-        uc = true;
-      }
-    }
-    co.len++;
-    tpos++;
-    // d << c;
-  }
-  if (co.len != 0) {
-    r.outputs.push_back(co);
+    if (isupper(c))
+      r.append(blue);
+    else
+      r.append(cyan);
   }
   return r;
 };
 
-door::renderFunction renderStatusValue(door::ANSIColor status,
-                                       door::ANSIColor value) {
-  door::renderFunction rf = [status,
-                             value](const std::string &txt) -> door::Render {
-    door::Render r(txt);
-    door::ColorOutput co;
-
-    co.pos = 0;
-    co.len = 0;
-    co.c = status;
-
-    size_t pos = txt.find(':');
-    if (pos == std::string::npos) {
-      // failed to find - use entire string as status color.
-      co.len = txt.length();
-      r.outputs.push_back(co);
-    } else {
-      pos++; // Have : in status color
-      co.len = pos;
-      r.outputs.push_back(co);
-      co.reset();
-      co.pos = pos;
-      co.c = value;
-      co.len = txt.length() - pos;
-      r.outputs.push_back(co);
-    }
-
-    return r;
-  };
-  return rf;
-}
-
-door::renderFunction rStatusValue = [](const std::string &txt) -> door::Render {
-  door::Render r(txt);
-  door::ColorOutput co;
-
-  // default colors STATUS: value
-  door::ANSIColor status(door::COLOR::BLUE, door::ATTR::BOLD);
-  door::ANSIColor value(door::COLOR::YELLOW, door::ATTR::BOLD);
-
-  co.pos = 0;
-  co.len = 0;
-  co.c = status;
-
-  size_t pos = txt.find(':');
-  if (pos == std::string::npos) {
-    // failed to find - use entire string as status color.
-    co.len = txt.length();
-    r.outputs.push_back(co);
-  } else {
-    pos++; // Have : in status color
-    co.len = pos;
-    r.outputs.push_back(co);
-    co.reset();
-    co.pos = pos;
-    co.c = value;
-    co.len = txt.length() - pos;
-    r.outputs.push_back(co);
-  }
-
-  return r;
-};
-
-/*
-std::function<void(Door &d, std::string &txt)> BlueYellow2 =
-    [](Door &d, std::string &txt) -> void {
-  bool uc = true;
-  ANSIColor blue(COLOR::BLACK, COLOR::CYAN);
-  ANSIColor cyan(COLOR::YELLOW, COLOR::BLUE, ATTR::BOLD);
-
-  d << blue;
-  for (char const &c : txt) {
-    if (uc) {
-      if (c == ':') {
-        d << cyan;
-        uc = false;
-      }
-    }
-    d << c;
-  }
-};
-
-std::function<void(Door &d, std::string &txt)> Aweful =
-    [](Door &d, std::string &txt) -> void {
-  for (char const &c : txt) {
-    // Color clr((Colors)((c % 14) + 1), Colors::BLACK, 0);
-    // Use only BRIGHT/LIGHT colors.
-    ANSIColor clr((COLOR)(c % 8), ATTR::BOLD);
-    d << clr << c;
-  }
-};
-*/
-
 } // namespace door

+ 0 - 9
door.h

@@ -661,23 +661,14 @@ public:
   void addSelection(char c, const char *line);
   void defaultSelection(int d);
   void setRender(bool selected, renderFunction render);
-  /*
-  void setColorizer(bool selected,
-                    std::function<void(Door &d, std::string &)> colorizer);
-  */
 
   int choose(Door &door);
   char which(int d);
 
   static renderFunction makeRender(ANSIColor c1, ANSIColor c2, ANSIColor c3,
                                    ANSIColor c4);
-
-  // static std::function<void(Door &d, std::string &)>
-  // makeColorizer(ANSIColor c1, ANSIColor c2, ANSIColor c3, ANSIColor c4);
 };
 
-renderFunction renderStatusValue(ANSIColor state, ANSIColor value);
-
 class Screen {
 private:
   // bool hidden;

+ 8 - 76
panel.cpp

@@ -489,95 +489,27 @@ renderFunction Menu::makeRender(ANSIColor c1, ANSIColor c2, ANSIColor c3,
     Render r(txt);
 
     bool option = true;
-    ColorOutput co;
-
-    /*
-      bool uc = true;
-      ANSIColor blue(COLOR::BLUE, ATTR::BOLD);
-      ANSIColor cyan(COLOR::YELLOW, ATTR::BOLD);
-    */
-
-    co.pos = 0;
-    co.len = 0;
-    co.c = c1;
-    // d << blue;
-
-    int tpos = 0;
     for (char const &c : txt) {
       if (option) {
         if (c == '[' or c == ']') {
-          if (co.c != c1)
-            if (co.len != 0) {
-              r.outputs.push_back(co);
-              co.reset();
-              co.pos = tpos;
-            }
-          co.c = c1;
-          if (c == ']')
-            option = false;
+          r.append(c1);
+          option = (c == '[');
         } else {
-          if (co.c != c2)
-            if (co.len != 0) {
-              r.outputs.push_back(co);
-              co.reset();
-              co.pos = tpos;
-            }
-          co.c = c2;
+          r.append(c2);
         }
       } else {
-        if (isupper(c)) {
-          // possible color change
-          if (co.c != c3)
-            if (co.len != 0) {
-              r.outputs.push_back(co);
-              co.reset();
-              co.pos = tpos;
-            }
-          co.c = c3;
-        } else {
-          if (co.c != c4)
-            if (co.len != 0) {
-              r.outputs.push_back(co);
-              co.reset();
-              co.pos = tpos;
-            }
-          co.c = c4;
-        }
+        if (isupper(c))
+          r.append(c3);
+        else
+          r.append(c4);
       }
-      co.len++;
-      tpos++;
-    }
-    if (co.len != 0) {
-      r.outputs.push_back(co);
     }
+
     return r;
   };
   return render;
 }
 
-/*
-std::function<void(Door &d, std::string &)>
-Menu::makeColorizer(ANSIColor c1, ANSIColor c2, ANSIColor c3, ANSIColor c4)
-{ std::function<void(Door & d, std::string & txt)> colorize = [c1, c2, c3,
-c4](Door &d, std::string txt) { bool option = true; for (char const &c :
-txt) { if (option) { if (c == '[' or c == ']') { d << c1 << c; if (c == ']')
-                option = false;
-            } else {
-              d << c2 << c;
-            }
-          } else {
-            if (isupper(c)) {
-              d << c3 << c;
-            } else {
-              d << c4 << c;
-            }
-          }
-        }
-      };
-  return colorize;
-}
-*/
-
 /*
   Should this return the index number, or
   the actual option?