소스 검색

[tmp][quickfix] moved write function to Curse??Output for new-line. atm work only for first win

isundil 9 년 전
부모
커밋
6556a5ac17
6개의 변경된 파일61개의 추가작업 그리고 40개의 파일을 삭제
  1. 1 1
      include/curseOutput.hh
  2. 1 0
      include/curseSimpleOutput.hh
  3. 1 0
      include/curseSplitOutput.hh
  4. 0 18
      src/curseOutput.cpp
  5. 22 5
      src/curseSimpleOutput.cpp
  6. 36 16
      src/curseSplitOutput.cpp

+ 1 - 1
include/curseOutput.hh

@@ -100,7 +100,7 @@ class CurseOutput
         /**
          * Warning: this one does not check line height, because he's not aware of cursor position
         **/
-        void write(const std::string &str, const OutputFlag flags) const;
+        virtual void write(const std::string &str, const OutputFlag flags) const =0;
         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;

+ 1 - 0
include/curseSimpleOutput.hh

@@ -44,6 +44,7 @@ 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 *);

+ 1 - 0
include/curseSplitOutput.hh

@@ -26,6 +26,7 @@ class CurseSplitOutput: public CurseOutput
         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);
         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 jumpToNextSearch(const JSonElement *current, bool &selectFound);
         bool jumpToNextSearch();

+ 0 - 18
src/curseOutput.cpp

@@ -110,24 +110,6 @@ unsigned int CurseOutput::write(const int &x, const int &y, JSonElement *item, u
     return write(x, y, item->stringify(), item->lazystrlen(), maxWidth, flags);
 }
 
-void CurseOutput::write(const std::string &str, const OutputFlag flags) const
-{
-    char color = OutputFlag::SPECIAL_NONE;
-    if (flags.selected())
-        attron(A_REVERSE | A_BOLD);
-    if (flags.searched())
-        color = OutputFlag::SPECIAL_SEARCH;
-    else if (colors.find(flags.type()) != colors.end())
-        color = flags.type();
-    if (color != OutputFlag::SPECIAL_NONE)
-        attron(COLOR_PAIR(color));
-
-    printw("%s", str.c_str());
-    attroff(A_REVERSE | A_BOLD);
-    if (color != OutputFlag::SPECIAL_NONE)
-        attroff(COLOR_PAIR(color));
-}
-
 unsigned int CurseOutput::getNbLines(const size_t nbChar, unsigned int maxWidth)
 {
     double nLine = (double) nbChar / maxWidth;

+ 22 - 5
src/curseSimpleOutput.cpp

@@ -19,7 +19,6 @@ CurseSimpleOutput::CurseSimpleOutput(const Params &p): CurseOutput(p)
     init();
 }
 
-
 CurseSimpleOutput::~CurseSimpleOutput()
 {
     shutdown();
@@ -320,7 +319,7 @@ bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, st
     flags.type(OutputFlag::TYPE_OBJKEY);
     cursor.second += write(cursor.first, cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
     flags.type(OutputFlag::TYPE_OBJ);
-    CurseOutput::write(": ", flags);
+    write(": ", flags);
     flags.type(oldType);
     return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second);
 }
@@ -336,9 +335,9 @@ bool CurseSimpleOutput::writeKey(const std::string &key, const size_t keylen, co
     flags.type(OutputFlag::TYPE_OBJKEY);
     write(cursor.first, cursor.second, key, 0, 1, flags);
     flags.type(OutputFlag::TYPE_OBJ);
-    CurseOutput::write(": ", flags);
+    write(": ", flags);
     flags.type(oldType);
-    CurseOutput::write(after.c_str(), flags);
+    write(after.c_str(), flags);
     cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxSize.first);
     return (cursor.second - scrollTop < 0 || (unsigned)(cursor.second - scrollTop) <= maxSize.second);
 }
@@ -373,10 +372,28 @@ unsigned int CurseSimpleOutput::write(const int &x, const int &y, const std::str
     if (offsetY < 0)
         return 1;
     move(offsetY, x);
-    CurseOutput::write(str, flags);
+    write(str, flags);
     return getNbLines(strlen +x, maxWidth);
 }
 
+void CurseSimpleOutput::write(const std::string &str, const OutputFlag flags) const
+{
+    char color = OutputFlag::SPECIAL_NONE;
+    if (flags.selected())
+        attron(A_REVERSE | A_BOLD);
+    if (flags.searched())
+        color = OutputFlag::SPECIAL_SEARCH;
+    else if (colors.find(flags.type()) != colors.end())
+        color = flags.type();
+    if (color != OutputFlag::SPECIAL_NONE)
+        attron(COLOR_PAIR(color));
+
+    printw("%s", str.c_str());
+    attroff(A_REVERSE | A_BOLD);
+    if (color != OutputFlag::SPECIAL_NONE)
+        attroff(COLOR_PAIR(color));
+}
+
 bool CurseSimpleOutput::jumpToNextSearch(const JSonElement *current, bool &selectFound)
 {
     const JSonContainer *container = dynamic_cast<const JSonContainer *> (current);

+ 36 - 16
src/curseSplitOutput.cpp

@@ -28,11 +28,12 @@ CurseSplitOutput::~CurseSplitOutput()
 void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::deque<JSonElement*> &roots)
 {
     nbInputs = inputName.size();
-    selectedWin = 0;
+    selectedWin = 2;
     scrollTop.clear();
     select_up.clear();
     select_down.clear();
     selection.clear();
+    search_result.clear();
     for (size_t i =0; i < nbInputs; i++)
     {
         this->roots.push_back(roots.at(i));
@@ -40,6 +41,7 @@ void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::
         selection.push_back(roots.at(i));
         select_up.push_back(nullptr);
         select_down.push_back(nullptr);
+        search_result.push_back(std::list<const JSonElement *>());
     }
     fileNames = inputName;
     loop();
@@ -56,7 +58,7 @@ Optional<bool> CurseSplitOutput::evalKey(int c)
         case KEY_UP:
         case 'K':
         case 'k':
-            selection = select_up;
+            selection[selectedWin] = select_up[selectedWin];
             return Optional<bool>::of(true);
 
         case KEY_DOWN:
@@ -65,7 +67,7 @@ Optional<bool> CurseSplitOutput::evalKey(int c)
             if (selectIsLast)
                 scrollTop[selectedWin] += 2;
             else if (selection != select_down)
-                selection = select_down;
+                selection[selectedWin] = select_down[selectedWin];
             else
                 break;
             return Optional<bool>::of(true);
@@ -275,13 +277,15 @@ bool CurseSplitOutput::redraw()
 
     destroyAllSubWin();
     clear();
+    refresh();
     for (workingWin =0; workingWin < nbInputs; workingWin++)
     {
-        std::pair<int, int> cursor(workingWin * screenSize.first + (workingWin ? 0 : 1), 0);
+        std::pair<int, int> cursor(workingWin * screenSize.first + (workingWin ? 0 : 1), 1);
         bool result;
 
         currentWin = newwin(screenSize.second, screenSize.first, 0, cursor.first -1);
         box(currentWin, 0, 0);
+        subwindows.push_back(currentWin);
         select_up[workingWin] = select_down[workingWin] = nullptr;
         selectFound = selectIsLast = false;
 
@@ -314,7 +318,6 @@ bool CurseSplitOutput::redraw()
             select_up[workingWin] = selection[workingWin];
         wrefresh(currentWin);
     }
-    refresh();
     return true;
 }
 
@@ -430,7 +433,7 @@ bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, std
     flags.type(OutputFlag::TYPE_OBJKEY);
     cursor.second += write(cursor.first, cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
     flags.type(OutputFlag::TYPE_OBJ);
-    CurseOutput::write(": ", flags);
+    write(": ", flags);
     flags.type(oldType);
     return (cursor.second - scrollTop[workingWin] < 0 || (unsigned)(cursor.second - scrollTop[workingWin]) <= maxSize.second);
 }
@@ -446,9 +449,9 @@ bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, con
     flags.type(OutputFlag::TYPE_OBJKEY);
     write(cursor.first, cursor.second, key, 0, 1, flags);
     flags.type(OutputFlag::TYPE_OBJ);
-    CurseOutput::write(": ", flags);
+    write(": ", flags);
     flags.type(oldType);
-    CurseOutput::write(after.c_str(), flags);
+    write(after, flags);
     cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxSize.first);
     return (cursor.second - scrollTop[workingWin] < 0 || (unsigned)(cursor.second - scrollTop[workingWin]) <= maxSize.second);
 }
@@ -479,18 +482,18 @@ unsigned int CurseSplitOutput::write(const int &x, const int &y, const char item
         return 1;
 
     if (flags.selected())
-        attron(A_REVERSE | A_BOLD);
+        wattron(currentWin, A_REVERSE | A_BOLD);
     if (flags.searched())
         color = OutputFlag::SPECIAL_SEARCH;
     else if (colors.find(flags.type()) != colors.end())
         color = flags.type();
 
     if (color != OutputFlag::SPECIAL_NONE)
-        attron(COLOR_PAIR(color));
-    mvprintw(offsetY, x, "%c", item);
-    attroff(A_REVERSE | A_BOLD);
+        wattron(currentWin, COLOR_PAIR(color));
+    mvwprintw(currentWin, offsetY, x, "%c", item);
+    wattroff(currentWin, A_REVERSE | A_BOLD);
     if (color != OutputFlag::SPECIAL_NONE)
-        attroff(COLOR_PAIR(color));
+        wattroff(currentWin, COLOR_PAIR(color));
     return getNbLines(x +1, maxWidth);
 }
 
@@ -499,11 +502,29 @@ unsigned int CurseSplitOutput::write(const int &x, const int &y, const std::stri
     int offsetY = y - scrollTop[workingWin];
     if (offsetY < 0)
         return 1;
-    move(offsetY, x);
-    CurseOutput::write(str, flags);
+    wmove(currentWin, offsetY, x);
+    write(str, flags);
     return getNbLines(strlen +x, maxWidth);
 }
 
+void CurseSplitOutput::write(const std::string &str, const OutputFlag flags) const
+{
+    char color = OutputFlag::SPECIAL_NONE;
+    if (flags.selected())
+        wattron(currentWin, A_REVERSE | A_BOLD);
+    if (flags.searched())
+        color = OutputFlag::SPECIAL_SEARCH;
+    else if (colors.find(flags.type()) != colors.end())
+        color = flags.type();
+    if (color != OutputFlag::SPECIAL_NONE)
+        wattron(currentWin, COLOR_PAIR(color));
+
+    wprintw(currentWin, "%s", str.c_str());
+    wattroff(currentWin, A_REVERSE | A_BOLD);
+    if (color != OutputFlag::SPECIAL_NONE)
+        wattroff(currentWin, COLOR_PAIR(color));
+}
+
 void CurseSplitOutput::destroyAllSubWin()
 {
     for (WINDOW *i: subwindows)
@@ -563,7 +584,6 @@ void CurseSplitOutput::init()
     signal(SIGINT, _resizeFnc);
     signal(SIGTERM, _resizeFnc);
     signal(SIGKILL, _resizeFnc);
-    scrollTop[selectedWin] = 0;
 }
 
 void CurseSplitOutput::shutdown()