Steve Thielemann 3 سال پیش
والد
کامیت
10714dc523
3فایلهای تغییر یافته به همراه9 افزوده شده و 140 حذف شده
  1. 2 2
      door.h
  2. 0 133
      getkey.cpp
  3. 7 5
      panel.cpp

+ 2 - 2
door.h

@@ -680,12 +680,12 @@ renderFunction renderStatusValue(ANSIColor state, ANSIColor value);
 class Screen {
 private:
   // bool hidden;
-  std::vector<std::shared_ptr<Panel>> parts;
+  std::vector<std::unique_ptr<Panel>> panels;
 
 public:
   Screen(void);
   Screen(Screen &) = default;
-  void addPanel(std::shared_ptr<Panel> p);
+  void addPanel(std::unique_ptr<Panel> p);
   /*
 bool delPanel(std::shared_ptr<Panel> p);
 

+ 0 - 133
getkey.cpp

@@ -253,136 +253,3 @@ signed int getkey(void) {
   }
   return c;
 }
-
-#ifdef JUNKY_MONKEY
-
-int nogetkey(void) {
-  char c;
-  if (read(STDIN_FILENO, &c, 1) == 1) {
-    std::cout << std::hex << (int)c << ":";
-
-    if (c == 0) {
-      std::cout << "0x00" CRNL;
-    }
-    std::cout.flush();
-
-    if (c == 0x1b) {
-      // Ok, this might be something special...
-      char buffer[5] = "";
-      int pos = 0;
-      while ((pos < sizeof(buffer) - 1) and
-             (read(STDIN_FILENO, &buffer[pos], 1) == 1)) {
-        std::cout << "~" << std::hex << (int)buffer[pos] << "~";
-        std::cout.flush();
-
-        pos++;
-        buffer[pos] = 0;
-      };
-
-      if (pos == 0)
-        return 0x1b;
-
-      // Ok, translate the keys
-      if (buffer[0] == '[') {
-        switch (buffer[1]) {
-        case 'A':
-          return XKEY_UP_ARROW;
-        case 'B':
-          return XKEY_DOWN_ARROW;
-        case 'C':
-          return XKEY_RIGHT_ARROW;
-        case 'D':
-          return XKEY_LEFT_ARROW;
-        }
-      }
-
-      std::cout << CRNL "DEBUG:" CRNL;
-      for (int x = 0; x < pos; x++) {
-        char z = buffer[x];
-        if (iscntrl(z)) {
-          std::cout << (int)z << " ";
-        } else {
-          std::cout << "'" << (char)z << "'"
-                    << " ";
-        };
-
-        // std::cout << (int)buffer[x] << ", ";
-      };
-
-      std::cout << CRNL;
-      std::cout.flush();
-      return 0x1000;
-    };
-    return (int)c;
-  }
-  return -1;
-  /*
-      if (iscntrl(c)) {
-        printf("%d\r\n", c);
-      } else {
-        printf("%d ('%c')\r\n", c, c);
-      }
-  */
-}
-
-int main(void) {
-  std::cout
-      << "\377\375\042\377\373\001"; //  "\xff\xfc\x22"; // IAC WONT LINEMODE
-  std::cout << "\x1b[2J\x1b[H";
-
-  raw();
-
-  std::cout << "\u2615"
-            << "\x1b[6n";
-
-  std::cout << "\x1b[999C\x1b[999B\x1b[6n";
-  std::cout.flush();
-
-  std::cout << "\x1b[2J\x1b[H";
-  std::cout << "isatty = " << isatty(STDIN_FILENO) << CRNL;
-
-  // no, I don't get a SIGHUP.  Hmm, maybe that's a "terminal" thing,
-  // and I'm not in a terminal...
-
-  // signal(SIGHUP, done);
-
-  // Ok!  Great!
-  signed int c = 0;
-  std::cout << "RAW MODE" CRNL;
-  std::cout.flush();
-
-  while (c != 'Q') {
-    c = getkey();
-    if (c >= 0) {
-      if (c == 0x1b) {
-        // This is ESC, so..
-        std::cout << "\x1b[6n";
-        std::cout.flush();
-      }
-      if (c > 256) {
-        std::cout << "[" << std::hex << c << "]";
-      } else {
-        if (iscntrl(c)) {
-          std::cout << int(c);
-        } else {
-          std::cout << int(c) << "('" << (char)c << "')";
-        }
-      }
-      std::cout << " ";
-      std::cout.flush();
-    }
-
-    /*
-    if (std::cin.eof()) {
-      std::cout << "BLARGH" CRNL;
-      break;
-    }
-    */
-  };
-
-  std::cout << CRNL "DONE" CRNL;
-
-  reset();
-}
-
-#endif

+ 7 - 5
panel.cpp

@@ -730,7 +730,9 @@ Screen::Screen(Screen &s) {
 }
 */
 
-void Screen::addPanel(std::shared_ptr<Panel> p) { parts.push_back(p); }
+void Screen::addPanel(std::unique_ptr<Panel> p) {
+  panels.push_back(std::move(p));
+}
 
 /*
 void Screen::hide(void) { hidden = true; }
@@ -739,7 +741,7 @@ void Screen::show(void) { hidden = false; }
 
 bool Screen::update(Door &d) {
   bool updated = false;
-  for (auto panel : parts) {
+  for (auto &panel : panels) {
     if (panel->update(d))
       updated = true;
   }
@@ -747,15 +749,15 @@ bool Screen::update(Door &d) {
 }
 
 void Screen::update(void) {
-  for (auto panel : parts) {
+  for (auto &panel : panels) {
     panel->update();
   }
 }
 
 std::ostream &operator<<(std::ostream &os, const Screen &s) {
   // if (!s.hidden) {
-  for (auto part : s.parts) {
-    os << *part;
+  for (auto &panel : s.panels) {
+    os << *panel;
   };
   // os << flush;
   // }