Bladeren bron

[add] handle screen resize

isundil 9 jaren geleden
bovenliggende
commit
656759fcb1
2 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. 2 2
      include/curseOutput.hh
  2. 6 0
      src/curseOutput.cpp

+ 2 - 2
include/curseOutput.hh

@@ -31,8 +31,8 @@ class CurseOutput
         bool readInput();
         void getScreenSize(std::pair<int, int> &, std::pair<int, int> &);
         static CurseOutput::t_nextKey findNext(const JSonElement *);
-        void write(const int &x, const int &y, const JSonElement *item, bool selected);
-        void write(const int &x, const int &y, const std::string &item, bool selected);
+        void write(const int &x, const int &y, const JSonElement *item, bool selected =false);
+        void write(const int &x, const int &y, const std::string &item, bool selected =false);
         void writeKey(const std::string &key, std::pair<int, int> &cursor, bool selected);
 
         const JSonElement *data, *selection;

+ 6 - 0
src/curseOutput.cpp

@@ -1,9 +1,11 @@
 #include<iostream>
 
+#include <sys/ioctl.h>
 #include <unistd.h>
 #include <signal.h>
 #include <string.h>
 #include <utility>
+
 #include "curseOutput.hh"
 #include "jsonObject.hh"
 #include "jsonArray.hh"
@@ -38,9 +40,13 @@ void CurseOutput::loop()
 
 bool CurseOutput::onsig(int signo)
 {
+    struct winsize size;
+
     switch (signo)
     {
     case SIGWINCH:
+        if (ioctl(fileno(screen_fd ? screen_fd : stdout), TIOCGWINSZ, &size) == 0)
+            resize_term(size.ws_row, size.ws_col);
         clear();
         redraw();
         break;