Bladeren bron

[TMP][refactor] probably broken, replaced all std::pair<> with typedef t_Cursor
[refactor] removed some useless abstract functions in the Splitted case from abstract class CurseOutput
[add] added Cursor in CurseSplitOutput#subWindow structure

B Thibault 9 jaren geleden
bovenliggende
commit
eb94148ad4
6 gewijzigde bestanden met toevoegingen van 144 en 120 verwijderingen
  1. 20 12
      include/curseOutput.hh
  2. 6 6
      include/curseSimpleOutput.hh
  3. 9 8
      include/curseSplitOutput.hh
  4. 8 8
      src/curseOutput.cpp
  5. 8 8
      src/curseSimpleOutput.cpp
  6. 93 78
      src/curseSplitOutput.cpp

+ 20 - 12
include/curseOutput.hh

@@ -30,6 +30,8 @@ enum inputResult: char
     ,nextInput  =3
 };
 
+typedef std::pair<unsigned int, unsigned int> t_Cursor;
+
 class CurseOutput
 {
     public:
@@ -69,8 +71,9 @@ class CurseOutput
         bool redraw(const std::string &errorMsg);
         /**
          * redraw item and children
-        **/
-        virtual bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxWidth, JSonElement *item) =0;
+        **
+        virtual bool redraw(t_Cursor &, const t_Cursor &maxWidth, JSonElement *item) =0;
+        */
 
         /**
          * Wait for input
@@ -92,13 +95,14 @@ class CurseOutput
         /**
          * get the screen size
         **/
-        virtual const std::pair<unsigned int, unsigned int> getScreenSize() const;
-        const std::pair<unsigned int, unsigned int> getScreenSizeUnsafe() const;
+        virtual const t_Cursor getScreenSize() const;
+        const t_Cursor getScreenSizeUnsafe() const;
 
         /**
          * set the select_up and select_down pointers, scroll to selection if it is above view port
-        **/
-        virtual void checkSelection(const JSonElement *item, const std::pair<int, int>&) =0;
+        **
+        virtual void checkSelection(const JSonElement *item, const t_Cursor &) =0;
+        */
 
         /**
          * Return the number of lines written while writting nbChar bytes
@@ -124,12 +128,16 @@ class CurseOutput
         unsigned int write(const int &x, const int &y, JSonElement *item, unsigned int maxWidth, const OutputFlag);
         virtual unsigned int write(const int &x, const int &y, const std::string &item, const size_t len, unsigned int maxWidth, const OutputFlag) =0;
         virtual unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, const OutputFlag) =0;
-        virtual bool writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag, unsigned int extraLen =0) =0;
-        virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag) =0;
-        virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag);
-
-        virtual bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *) =0;
-        virtual bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement *> * obj) =0;
+        /*
+        virtual bool writeKey(const std::string &key, const size_t keylen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag, unsigned int extraLen =0) =0;
+        */
+        virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag) =0;
+        virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);
+
+        /*
+        virtual bool writeContainer(t_Cursor &, const t_Cursor &maxSize, const JSonContainer *) =0;
+        virtual bool writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement *> * obj) =0;
+        */
 
         /**
          * prompt for user input, and return it

+ 6 - 6
include/curseSimpleOutput.hh

@@ -40,12 +40,12 @@ class CurseSimpleOutput: public CurseOutput
         unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
         unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
         void write(const std::string &str, const OutputFlag flags) const;
-        bool writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxWidth, OutputFlag, unsigned int extraLen =0);
-        bool writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags);
-        bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *);
-        bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement *> * obj);
-        bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &, JSonElement *);
-        void checkSelection(const JSonElement *item, const std::pair<int, int> &cursor);
+        bool writeKey(const std::string &key, const size_t keylen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag, unsigned int extraLen =0);
+        bool writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, t_Cursor &cursor, const t_Cursor &maxSize, OutputFlag flags);
+        bool writeContainer(t_Cursor &, const t_Cursor &maxSize, const JSonContainer *);
+        bool writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement *> * obj);
+        bool redraw(t_Cursor &, const t_Cursor &, JSonElement *);
+        void checkSelection(const JSonElement *item, const t_Cursor &cursor);
 
     protected:
         inputResult selectUp();

+ 9 - 8
include/curseSplitOutput.hh

@@ -14,6 +14,7 @@ typedef struct
     WINDOW *innerWin, *outerWin;
     std::list<const JSonElement*> searchResults;
     int scrollTop;
+    t_Cursor cursor;
 } t_subWindow;
 
 class CurseSplitOutput: public CurseOutput
@@ -27,18 +28,18 @@ class CurseSplitOutput: public CurseOutput
         **/
         void run(const std::deque<std::string> &, const std::deque<JSonElement *> &);
 
-        void checkSelection(const JSonElement *item, const std::pair<int, int> &cursor);
+        void checkSelection(const JSonElement *item);
 
         void loop();
 
         bool redraw();
-        bool redraw(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &, JSonElement *);
-        bool redrawCurrent(const std::pair<unsigned int, unsigned int> &screenSize);
+        bool redraw(const t_Cursor &screenSize, JSonElement *);
+        bool redrawCurrent(const t_Cursor &screenSize);
 
-        bool writeContainer(std::pair<int, int> &, const std::pair<unsigned int, unsigned int> &, const JSonContainer *);
-        bool writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement*> *_item);
-        bool writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags, unsigned int extraLen =0);
-        bool writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags);
+        bool writeContainer(const t_Cursor &maxSize, const JSonContainer *);
+        bool writeContent(const t_Cursor &maxSize, std::list<JSonElement*> *_item);
+        bool writeKey(const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen =0);
+        bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);
         unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, OutputFlag flags);
         unsigned int write(const int &x, const int &y, const std::string &str, const size_t strlen, unsigned int maxWidth, const OutputFlag flags);
         void write(const std::string &str, const OutputFlag flags) const;
@@ -53,7 +54,7 @@ class CurseSplitOutput: public CurseOutput
         /**
          * get the screen size
         **/
-        const std::pair<unsigned int, unsigned int> getScreenSize() const;
+        const t_Cursor getScreenSize() const;
 
         /**
          * Release ncurses

+ 8 - 8
src/curseOutput.cpp

@@ -143,7 +143,7 @@ bool CurseOutput::redraw(const std::string &errorMsg)
     return result;
 }
 
-bool CurseOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
+bool CurseOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, const t_Cursor &maxSize, OutputFlag flags)
 {
     return writeKey(key, keylen, after, after.size(), cursor, maxSize, flags);
 }
@@ -161,15 +161,15 @@ unsigned int CurseOutput::getNbLines(const size_t nbChar, unsigned int maxWidth)
     return nLine +1;
 }
 
-const std::pair<unsigned int, unsigned int> CurseOutput::getScreenSize() const
+const t_Cursor CurseOutput::getScreenSize() const
 {
     return getScreenSizeUnsafe();
 }
 
-const std::pair<unsigned int, unsigned int> CurseOutput::getScreenSizeUnsafe() const
+const t_Cursor CurseOutput::getScreenSizeUnsafe() const
 {
-    std::pair<int, int> bs;
-    std::pair<int, int> sc;
+    t_Cursor bs;
+    t_Cursor sc;
     getmaxyx(stdscr, sc.second, sc.first);
     getbegyx(stdscr, bs.second, bs.first);
     sc.first -= bs.first;
@@ -230,7 +230,7 @@ const SearchPattern *CurseOutput::inputSearch()
 
 void CurseOutput::writeTopLine(const std::string &buffer, short color) const
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
+    const t_Cursor screenSize = getScreenSize();
     const size_t bufsize = buffer.size();
 
     if (params.colorEnabled())
@@ -242,7 +242,7 @@ void CurseOutput::writeTopLine(const std::string &buffer, short color) const
 
 void CurseOutput::writeBottomLine(const std::string &buffer, short color) const
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSizeUnsafe();
+    const t_Cursor screenSize = getScreenSizeUnsafe();
     const size_t bufsize = buffer.size();
 
     if (params.colorEnabled())
@@ -255,7 +255,7 @@ void CurseOutput::writeBottomLine(const std::string &buffer, short color) const
 
 void CurseOutput::writeBottomLine(const std::wstring &buffer, short color) const
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSizeUnsafe();
+    const t_Cursor screenSize = getScreenSizeUnsafe();
     const size_t bufsize = buffer.size();
 
     if (params.colorEnabled())

+ 8 - 8
src/curseSimpleOutput.cpp

@@ -34,8 +34,8 @@ void CurseSimpleOutput::run(JSonElement *root, const std::string &i)
 
 bool CurseSimpleOutput::redraw()
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
-    std::pair<int, int> cursor(0, 1);
+    const t_Cursor screenSize = getScreenSize();
+    t_Cursor cursor(0, 1);
     /**
      * Will be true if the json's last item is visible
     **/
@@ -191,7 +191,7 @@ inputResult CurseSimpleOutput::changeWindow(char, bool)
     return inputResult::nextInput;
 }
 
-bool CurseSimpleOutput::redraw(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, JSonElement *item)
+bool CurseSimpleOutput::redraw(t_Cursor &cursor, const t_Cursor &maxSize, JSonElement *item)
 {
     checkSelection(item, cursor);
     if (dynamic_cast<const JSonContainer*>(item))
@@ -208,7 +208,7 @@ bool CurseSimpleOutput::redraw(std::pair<int, int> &cursor, const std::pair<unsi
     return true;
 }
 
-bool CurseSimpleOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *item)
+bool CurseSimpleOutput::writeContainer(t_Cursor &cursor, const t_Cursor &maxSize, const JSonContainer *item)
 {
     char childDelimiter[2];
 
@@ -235,7 +235,7 @@ bool CurseSimpleOutput::writeContainer(std::pair<int, int> &cursor, const std::p
     return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second -1);
 }
 
-bool CurseSimpleOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement*> *_item)
+bool CurseSimpleOutput::writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement*> *_item)
 {
     JSonContainer *item = (JSonContainer *)_item;
     bool containerIsObject = (dynamic_cast<JSonObject *>(item) != nullptr);
@@ -307,7 +307,7 @@ bool CurseSimpleOutput::writeContent(std::pair<int, int> &cursor, const std::pai
     return result;
 }
 
-bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags, unsigned int extraLen)
+bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, t_Cursor &cursor, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen)
 {
     if (cursor.second - scrollTop <= 0)
     {
@@ -323,7 +323,7 @@ bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, st
     return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second);
 }
 
-bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
+bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, t_Cursor &cursor, const t_Cursor &maxSize, OutputFlag flags)
 {
     if (cursor.second - scrollTop <= 0)
     {
@@ -493,7 +493,7 @@ bool CurseSimpleOutput::jumpToNextSearch()
     return true;
 }
 
-void CurseSimpleOutput::checkSelection(const JSonElement *item, const std::pair<int, int> &cursor)
+void CurseSimpleOutput::checkSelection(const JSonElement *item, const t_Cursor &cursor)
 {
     if (!selectFound)
     {

+ 93 - 78
src/curseSplitOutput.cpp

@@ -199,29 +199,31 @@ inputResult CurseSplitOutput::changeWindow(char d, bool c)
     return inputResult::redrawAll;
 }
 
-void CurseSplitOutput::checkSelection(const JSonElement *item, const std::pair<int, int> &cursor)
+void CurseSplitOutput::checkSelection(const JSonElement *item)
 {
+    t_subWindow &w = subWindows.at(workingWin);
+
     if (!selectFound)
     {
-        if (subWindows.at(workingWin).selection == item)
+        if (w.selection == item)
         {
-            if (cursor.second < subWindows.at(workingWin).scrollTop) //Selection is above vp, move scroll pos to selection and start drawing
-                subWindows.at(workingWin).scrollTop = cursor.second;
+            if (w.scrollTop > 0 && w.cursor.second < w.scrollTop) //Selection is above vp, move scroll pos to selection and start drawing
+                w.scrollTop = w.cursor.second;
             selectFound = true;
         }
         else if (!item->getParent() || !dynamic_cast<const JSonObjectEntry*>(item->getParent()))
-            subWindows.at(workingWin).select_up = item;
+            w.select_up = item;
     }
-    else if (!subWindows.at(workingWin).select_down)
+    else if (!w.select_down)
     {
         const JSonElement *parent = item->getParent();
         if (!dynamic_cast<const JSonContainer*>(item) &&
                 parent &&
-                subWindows.at(workingWin).selection != parent &&
+                w.selection != parent &&
                 dynamic_cast<const JSonObjectEntry*>(parent))
             item = parent;
         if (!parent || !dynamic_cast<const JSonObjectEntry*>(parent))
-            subWindows.at(workingWin).select_down = item;
+            w.select_down = item;
     }
 }
 
@@ -309,20 +311,20 @@ bool CurseSplitOutput::jumpToNextSearch()
     return true;
 }
 
-bool CurseSplitOutput::redrawCurrent(const std::pair<unsigned int, unsigned int> &screenSize)
+bool CurseSplitOutput::redrawCurrent(const t_Cursor &screenSize)
 {
-    std::pair<int, int> cursor(0, 1);
     bool result;
+    t_subWindow &w = subWindows.at(workingWin);
 
-    subWindows.at(workingWin).select_up = subWindows.at(workingWin).select_down = nullptr;
+    w.select_up = w.select_down = nullptr;
     selectFound = selectIsLast = false;
 
-    wclear(subWindows.at(workingWin).innerWin);
-    box(subWindows.at(workingWin).outerWin, 0, 0);
-    writeTopLine(subWindows.at(workingWin).fileName,
+    wclear(w.innerWin);
+    box(w.outerWin, 0, 0);
+    writeTopLine(w.fileName,
             workingWin == selectedWin ? OutputFlag::SPECIAL_ACTIVEINPUTNAME : OutputFlag::SPECIAL_INPUTNAME);
     try {
-        result = redraw(cursor, screenSize, subWindows.at(workingWin).root);
+        result = redraw(screenSize, w.root);
     }
     catch (SelectionOutOfRange &e)
     {
@@ -330,51 +332,57 @@ bool CurseSplitOutput::redrawCurrent(const std::pair<unsigned int, unsigned int>
     }
     if (!result && !selectFound)
     {
-        subWindows.at(workingWin).scrollTop++;
+        w.scrollTop++;
         return false;
     }
-    if (!result && !subWindows.at(workingWin).select_down)
+    if (!result && !w.select_down)
         selectIsLast = true;
-    if (!subWindows.at(workingWin).select_down)
+    if (!w.select_down)
     {
-        const JSonContainer *pselect = dynamic_cast<const JSonContainer*>(subWindows.at(workingWin).selection);
+        const JSonContainer *pselect = dynamic_cast<const JSonContainer*>(w.selection);
         if (pselect && !pselect->empty())
-            subWindows.at(workingWin).select_down = *(pselect->cbegin());
+            w.select_down = *(pselect->cbegin());
         else
         {
-            const JSonElement *next = subWindows.at(workingWin).selection->findNext();
-            subWindows.at(workingWin).select_down = next ? next : subWindows.at(workingWin).selection;
+            const JSonElement *next = w.selection->findNext();
+            w.select_down = next ? next : w.selection;
         }
     }
-    if (!subWindows.at(workingWin).select_up)
-        subWindows.at(workingWin).select_up = subWindows.at(workingWin).selection;
-    wrefresh(subWindows.at(workingWin).outerWin);
-    wrefresh(subWindows.at(workingWin).innerWin);
+    if (!w.select_up)
+        w.select_up = subWindows.at(workingWin).selection;
+    wrefresh(w.outerWin);
+    wrefresh(w.innerWin);
     return true;
 }
 
 bool CurseSplitOutput::redraw()
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
+    const t_Cursor screenSize = getScreenSize();
 
-    destroyAllSubWin();
+    destroyAllSubWin(); //TODO move to dtor ?
     clear();
     refresh();
-    for (workingWin =0; workingWin < nbInputs; workingWin++)
+    workingWin = 0;
+    for (t_subWindow &w : subWindows)
     {
-        //TODO JSonElement by JSonElement instead of file per file
+        w.cursor = t_Cursor(0, 1);
+        //TODO move below to ctor ?
         subWindows.at(workingWin).outerWin = newwin(screenSize.second +2, screenSize.first, 0, workingWin * screenSize.first -workingWin);
         subWindows.at(workingWin).innerWin = newwin(screenSize.second, screenSize.first -2, 1, workingWin * screenSize.first -workingWin +1);
+    }
+    for (t_subWindow &w : subWindows)
+    {
+        //TODO JSonElement by JSonElement instead of file per file
         if (!redrawCurrent(screenSize))
             return false;
     }
     return true;
 }
 
-bool CurseSplitOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, const JSonContainer *item)
+bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, const JSonContainer *item)
 {
     char childDelimiter[2];
-    const int scrollTop = subWindows.at(workingWin).scrollTop;
+    t_subWindow &w = subWindows.at(workingWin);
 
     if (dynamic_cast<const JSonObject *>(item))
         memcpy(childDelimiter, "{}", sizeof(*childDelimiter) * 2);
@@ -385,27 +393,29 @@ bool CurseSplitOutput::writeContainer(std::pair<int, int> &cursor, const std::pa
     {
         std::string ss;
         ss.append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
-        cursor.second += write(cursor.first, cursor.second, ss, 7, maxSize.first, CurseSplitOutput::getFlag(item));
+        w.cursor.second += write(w.cursor.first, w.cursor.second, ss, 7, maxSize.first, CurseSplitOutput::getFlag(item));
     }
     else
     {
-        cursor.second += write(cursor.first, cursor.second, childDelimiter[0], maxSize.first, CurseSplitOutput::getFlag(item));
-        if (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1)
+        w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[0], maxSize.first, CurseSplitOutput::getFlag(item));
+        if (w.cursor.second - w.scrollTop > 0 && (w.cursor.second - w.scrollTop) > maxSize.second -1)
                 return false;
-        if (!writeContent(cursor, maxSize, (std::list<JSonElement *> *)item))
+        if (!writeContent(maxSize, (std::list<JSonElement *> *)item))
             return false;
-        cursor.second += write(cursor.first, cursor.second, childDelimiter[1], maxSize.first, CurseSplitOutput::getFlag(item));
+        w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[1], maxSize.first, CurseSplitOutput::getFlag(item));
     }
-    return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second -1);
+    return ((w.scrollTop > 0 && w.cursor.second < w.scrollTop) ||
+            (w.cursor.second - w.scrollTop) <= maxSize.second -1);
 }
 
-bool CurseSplitOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, std::list<JSonElement*> *_item)
+bool CurseSplitOutput::writeContent(const t_Cursor &maxSize, std::list<JSonElement*> *_item)
 {
+    t_subWindow &w = subWindows.at(workingWin);
     JSonContainer *item = (JSonContainer *)_item;
     bool containerIsObject = (dynamic_cast<JSonObject *>(item) != nullptr);
     bool result = true;
-    cursor.first += INDENT_LEVEL;
-    const int scrollTop = subWindows.at(workingWin).scrollTop;
+    w.cursor.first += INDENT_LEVEL;
+    const int scrollTop = w.scrollTop;
 
     for (JSonElement *i : *item)
     {
@@ -415,82 +425,86 @@ bool CurseSplitOutput::writeContent(std::pair<int, int> &cursor, const std::pair
             JSonObjectEntry *ent = (JSonObjectEntry*) i;
             bool isContainer = (dynamic_cast<JSonContainer *>(**ent) != nullptr);
             std::string key = ent->stringify();
-            checkSelection(ent, cursor);
+            checkSelection(ent);
             if (isContainer && collapsed.find((JSonContainer*)(**ent)) != collapsed.cend())
             {
                 if (dynamic_cast<JSonObject *>(**ent))
                 {
-                    if (!CurseOutput::writeKey(key, ent->lazystrlen(), "{ ... }", cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
+                    if (!CurseOutput::writeKey(key, ent->lazystrlen(), "{ ... }", w.cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (w.cursor.second - scrollTop > 0 && (w.cursor.second - scrollTop) > maxSize.second -1))
                         break;
                 }
-                else if (!CurseOutput::writeKey(key, ent->lazystrlen(), "[ ... ]", cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
+                else if (!CurseOutput::writeKey(key, ent->lazystrlen(), "[ ... ]", w.cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (w.cursor.second - scrollTop > 0 && (w.cursor.second - scrollTop) > maxSize.second -1))
                     break;
             }
             else if (!isContainer)
             {
                 JSonElement *eContent = **ent;
-                if (!writeKey(key, ent->lazystrlen(), eContent->stringify(), eContent->lazystrlen(), cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
+                if (!writeKey(key, ent->lazystrlen(), eContent->stringify(), eContent->lazystrlen(), w.cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (w.cursor.second - scrollTop > 0 && (w.cursor.second - scrollTop) > maxSize.second -1))
                     break;
             }
             else if (((JSonContainer*)(**ent))->size() == 0)
             {
                 if (dynamic_cast<const JSonObject *>(**ent) )
                 {
-                    if (!CurseOutput::writeKey(key, ent->lazystrlen(), "{ }", cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
+                    if (!CurseOutput::writeKey(key, ent->lazystrlen(), "{ }", w.cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (w.cursor.second - scrollTop > 0 && (w.cursor.second - scrollTop) > maxSize.second -1))
                         break;
                 }
-                else if (!CurseOutput::writeKey(key, ent->lazystrlen(), "[ ]", cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
+                else if (!CurseOutput::writeKey(key, ent->lazystrlen(), "[ ]", w.cursor, maxSize, CurseSplitOutput::getFlag(ent)) || (w.cursor.second - scrollTop > 0 && (w.cursor.second - scrollTop) > maxSize.second -1))
                     break;
             }
             else
             {
-                if (!writeKey(key, ent->lazystrlen(), cursor, maxSize, getFlag(ent)))
+                if (!writeKey(key, ent->lazystrlen(), maxSize, getFlag(ent)))
                     break;
-                const JSonElement *saveSelection = subWindows.at(workingWin).selection;
+                const JSonElement *saveSelection = w.selection;
                 if (saveSelection == ent)
-                    subWindows.at(workingWin).selection = **ent;
-                cursor.first += INDENT_LEVEL /2;
-                if (!redraw(cursor, maxSize, **ent))
+                    w.selection = **ent;
+                w.cursor.first += INDENT_LEVEL /2;
+                if (!redraw(maxSize, **ent))
                 {
-                    subWindows.at(workingWin).selection = saveSelection;
-                    cursor.first -= INDENT_LEVEL /2;
+                    w.selection = saveSelection;
+                    w.cursor.first -= INDENT_LEVEL /2;
                     return false;
                 }
-                subWindows.at(workingWin).selection = saveSelection;
-                cursor.first -= INDENT_LEVEL /2;
+                w.selection = saveSelection;
+                w.cursor.first -= INDENT_LEVEL /2;
             }
         }
         else
         {
-            if (!redraw(cursor, maxSize, i))
+            if (!redraw(maxSize, i))
                 break;
         }
         result = true;
     }
-    cursor.first -= INDENT_LEVEL;
+    w.cursor.first -= INDENT_LEVEL;
     //result will be false if for loop break'd at some time, true otherwise
     return result;
 }
 
-bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags, unsigned int extraLen)
+bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen)
 {
-    if (cursor.second - subWindows.at(workingWin).scrollTop <= 0)
+    t_subWindow &w = subWindows.at(workingWin);
+
+    if (w.cursor.second - w.scrollTop <= 0)
     {
-        cursor.second++;
+        w.cursor.second++;
         return true;
     }
     char oldType = flags.type();
     flags.type(OutputFlag::TYPE_OBJKEY);
-    cursor.second += write(cursor.first, cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
+    w.cursor.second += write(w.cursor.first, w.cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
     flags.type(OutputFlag::TYPE_OBJ);
     write(": ", flags);
     flags.type(oldType);
-    return (cursor.second - subWindows.at(workingWin).scrollTop < 0 || (unsigned)(cursor.second - subWindows.at(workingWin).scrollTop) <= maxSize.second);
+    return (w.cursor.second - w.scrollTop < 0 || (w.cursor.second - w.scrollTop) <= maxSize.second);
 }
 
-bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, size_t afterlen, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
+bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag flags)
 {
-    if (cursor.second - subWindows.at(workingWin).scrollTop <= 0)
+    t_subWindow &w = subWindows.at(workingWin);
+
+    if (cursor.second - w.scrollTop <= 0)
     {
         cursor.second++;
         return true;
@@ -502,22 +516,24 @@ bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, con
     write(": ", flags);
     flags.type(oldType);
     write(after, flags);
-    cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxSize.first);
-    return (cursor.second - subWindows.at(workingWin).scrollTop < 0 || (unsigned)(cursor.second - subWindows.at(workingWin).scrollTop) <= maxSize.second);
+    cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxWidth.first);
+    return (cursor.second - w.scrollTop < 0 || (cursor.second - w.scrollTop) <= maxWidth.second);
 }
 
-bool CurseSplitOutput::redraw(std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, JSonElement *item)
+bool CurseSplitOutput::redraw(const t_Cursor &maxSize, JSonElement *item)
 {
-    checkSelection(item, cursor);
+    t_subWindow &w = subWindows.at(workingWin);
+
+    checkSelection(item);
     if (dynamic_cast<const JSonContainer*>(item))
     {
-        if (!writeContainer(cursor, maxSize, (const JSonContainer *) item))
+        if (!writeContainer(maxSize, (const JSonContainer *) item))
             return false;
     }
     else
     {
-        cursor.second += CurseOutput::write(cursor.first, cursor.second, item, maxSize.first, CurseSplitOutput::getFlag(item));
-        if (cursor.second - subWindows.at(workingWin).scrollTop > 0 && (unsigned)(cursor.second - subWindows.at(workingWin).scrollTop) > maxSize.second -1)
+        w.cursor.second += CurseOutput::write(w.cursor.first, w.cursor.second, item, maxSize.first, CurseSplitOutput::getFlag(item));
+        if (w.cursor.second - w.scrollTop > 0 && (w.cursor.second - w.scrollTop) > maxSize.second -1)
             return false;
     }
     return true;
@@ -600,7 +616,7 @@ void CurseSplitOutput::destroyAllSubWin()
 
 void CurseSplitOutput::writeTopLine(const std::string &buffer, short color) const
 {
-    const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
+    const t_Cursor screenSize = getScreenSize();
     const size_t bufsize = buffer.size();
     WINDOW *currentWin = subWindows.at(workingWin).innerWin;
 
@@ -611,16 +627,15 @@ void CurseSplitOutput::writeTopLine(const std::string &buffer, short color) cons
         wattroff(currentWin, COLOR_PAIR(color));
 }
 
-const std::pair<unsigned int, unsigned int> CurseSplitOutput::getScreenSize() const
+const t_Cursor CurseSplitOutput::getScreenSize() const
 {
-    std::pair<unsigned int, unsigned int> result = getScreenSizeUnsafe();
-    result.first /= nbInputs;
-    result.second -=2 ;
-    return result;
+    t_Cursor result = getScreenSizeUnsafe();
+    return t_Cursor(result.first / nbInputs, result.second -2);
 }
 
 void CurseSplitOutput::shutdown()
 {
+    destroyAllSubWin();
     endwin();
     delscreen(screen);
     if (screen_fd)