Kaynağa Gözat

[refactor] moved screenSize to curseOutput

B Thibault 9 yıl önce
ebeveyn
işleme
5a71b42c45

+ 4 - 2
include/curseOutput.hh

@@ -63,7 +63,7 @@ class CurseOutput
         /**
          * Called before redraw after window got SIGWINCH'd
         **/
-        virtual void onResizeHandler(const t_Cursor &);
+        virtual void onResizeHandler();
 
         /**
          * return false if bottom of screen is touched
@@ -100,7 +100,7 @@ class CurseOutput
         /**
          * get the screen size
         **/
-        virtual const t_Cursor getScreenSize() const;
+        virtual const t_Cursor getScreenSize() const =0;
         const t_Cursor getScreenSizeUnsafe() const;
 
         /**
@@ -185,6 +185,8 @@ class CurseOutput
         **/
         std::set<char /* OutputFlag::TYPE_SOMETHING */> colors;
 
+        t_Cursor screenSize;
+
         class SelectionOutOfRange { };
 };
 

+ 1 - 4
include/curseSimpleOutput.hh

@@ -30,6 +30,7 @@ class CurseSimpleOutput: public CurseOutput
         **/
         void shutdown();
 
+        const t_Cursor getScreenSize() const;
         /**
          * get flags to be passed to write.
          * Contains indications on who to write item
@@ -59,8 +60,6 @@ class CurseSimpleOutput: public CurseOutput
         inputResult nextResult();
         inputResult changeWindow(char, bool);
 
-        void onResizeHandler(const t_Cursor &newSize);
-
         /**
          * Root item
         **/
@@ -92,7 +91,5 @@ class CurseSimpleOutput: public CurseOutput
          * Used for moving viewport
         **/
         bool selectFound, selectIsLast;
-
-        t_Cursor screenSize;
 };
 

+ 1 - 3
include/curseSplitOutput.hh

@@ -90,7 +90,7 @@ class CurseSplitOutput: public CurseOutput
         inputResult nextResult();
         inputResult changeWindow(char, bool);
 
-        void onResizeHandler(const t_Cursor &);
+        void onResizeHandler();
 
         void setSelection(const JSonElement *);
 
@@ -106,8 +106,6 @@ class CurseSplitOutput: public CurseOutput
          * Viewport start
         **/
         unsigned short nbInputs, selectedWin, workingWin;
-
-        t_Cursor screenSize;
         // TODO t_subWindow &workingSubwin, &selectedSubwin ??
 };
 

+ 4 - 7
src/curseOutput.cpp

@@ -48,7 +48,7 @@ void CurseOutput::loop(WINDOW * w)
     } while (read != inputResult::quit);
 }
 
-void CurseOutput::onResizeHandler(const t_Cursor &)
+void CurseOutput::onResizeHandler()
 {
     clear();
 }
@@ -63,7 +63,8 @@ bool CurseOutput::onsig(int signo)
     case SIGWINCH:
         if (ioctl(fileno(screen_fd ? screen_fd : stdout), TIOCGWINSZ, &size) == 0)
             resize_term(size.ws_row, size.ws_col);
-        onResizeHandler(getScreenSize());
+        screenSize = getScreenSize();
+        onResizeHandler();
         while (!redraw());
         break;
 
@@ -174,11 +175,6 @@ unsigned int CurseOutput::getNbLines(const size_t nbChar, unsigned int maxWidth)
     return nLine +1;
 }
 
-const t_Cursor CurseOutput::getScreenSize() const
-{
-    return getScreenSizeUnsafe();
-}
-
 const t_Cursor CurseOutput::getScreenSizeUnsafe() const
 {
     t_Cursor bs;
@@ -298,6 +294,7 @@ void CurseOutput::init()
     noecho();
     curs_set(false);
     keypad(stdscr, true);
+    screenSize = getScreenSize();
 
     if (params.colorEnabled())
     {

+ 4 - 6
src/curseSimpleOutput.cpp

@@ -29,7 +29,6 @@ void CurseSimpleOutput::run(JSonElement *root, const std::string &i)
     scrollTop = 0;
     selection = data = root;
     inputName = i;
-    screenSize = getScreenSize();
     loop(nullptr);
 }
 
@@ -76,11 +75,6 @@ bool CurseSimpleOutput::redraw()
     return true;
 }
 
-void CurseSimpleOutput::onResizeHandler(const t_Cursor &ss)
-{
-    screenSize = t_Cursor(ss);
-}
-
 inputResult CurseSimpleOutput::selectUp()
 {
     selection = select_up;
@@ -538,4 +532,8 @@ void CurseSimpleOutput::shutdown()
     screen = nullptr;
 }
 
+const t_Cursor CurseSimpleOutput::getScreenSize() const
+{
+    return getScreenSizeUnsafe();
+}
 

+ 2 - 3
src/curseSplitOutput.cpp

@@ -41,10 +41,10 @@ CurseSplitOutput::~CurseSplitOutput()
 void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::deque<JSonElement*> &roots)
 {
     nbInputs = inputName.size();
-    screenSize = getScreenSize();
     selectedWin = 0;
     destroyAllSubWin();
     subWindows.clear();
+    screenSize = getScreenSize(); // screenSize is based on nbInputs, we must refresh it
 
     for (size_t i =0; i < nbInputs; ++i)
     {
@@ -413,12 +413,11 @@ const Optional<bool> CurseSplitOutput::redrawOneItemToWorkingWin(t_subWindow &w)
     return Optional<bool>::of(false);
 }
 
-void CurseSplitOutput::onResizeHandler(const t_Cursor &screenSize)
+void CurseSplitOutput::onResizeHandler()
 {
     size_t i =0;
     destroyAllSubWin();
     clear();
-    this->screenSize = t_Cursor(screenSize);
 
     for (t_subWindow &subwin: subWindows)
     {