Sfoglia il codice sorgente

[bugfix] select in splitted view

isundil 9 anni fa
parent
commit
a17372a0f0
4 ha cambiato i file con 60 aggiunte e 31 eliminazioni
  1. 1 1
      include/curseOutput.hh
  2. 5 0
      include/curseSplitOutput.hh
  3. 10 6
      src/curseOutput.cpp
  4. 44 24
      src/curseSplitOutput.cpp

+ 1 - 1
include/curseOutput.hh

@@ -140,7 +140,7 @@ class CurseOutput
          * prompt for user input, and return it
          * @throws noInputException if user use a kill-key (to exit buffer)
         **/
-        const SearchPattern *inputSearch();
+        const SearchPattern *inputSearch(WINDOW *w =nullptr);
 
         /**
          * find occurences of search result and fill this#search_result

+ 5 - 0
include/curseSplitOutput.hh

@@ -57,6 +57,10 @@ class CurseSplitOutput: public CurseOutput
 
         bool jumpToNextSearch(const JSonElement *current, bool &selectFound);
         bool jumpToNextSearch();
+
+        virtual void writeBottomLine(const std::string &currentBuffer, short color) const;
+        virtual void writeBottomLine(const std::wstring &currentBuffer, short color) const;
+
         unsigned int search(const SearchPattern &searchPattern);
         unsigned int search(const SearchPattern &searchPattern, const JSonElement *current);
 
@@ -106,6 +110,7 @@ class CurseSplitOutput: public CurseOutput
          * Viewport start
         **/
         unsigned short nbInputs, selectedWin, workingWin;
+        WINDOW *bottomLine;
         // TODO t_subWindow &workingSubwin, &selectedSubwin ??
 };
 

+ 10 - 6
src/curseOutput.cpp

@@ -158,6 +158,7 @@ inputResult CurseOutput::evalKey(const InputSequence &c)
 bool CurseOutput::redraw(const std::string &errorMsg)
 {
     bool result = redraw();
+
     writeBottomLine(errorMsg, OutputFlag::SPECIAL_ERROR);
     return result;
 }
@@ -200,21 +201,22 @@ void CurseOutput::unfold(const JSonElement *item)
     }
 }
 
-const SearchPattern *CurseOutput::inputSearch()
+const SearchPattern *CurseOutput::inputSearch(WINDOW *w)
 {
     std::wstring buffer;
     bool abort = false;
+    if (!w)
+        w = stdscr;
 
     curs_set(true);
-    wtimeout(stdscr, -1);
+    wtimeout(w, -1);
     while (!abort)
     {
         int c;
 
         writeBottomLine(L'/' +buffer, OutputFlag::SPECIAL_SEARCH);
-        refresh();
-        c = getwchar();
-        if (c == L'\r')
+        c = wgetch(w);
+        if (c == L'\n' || c == L'\r')
             break;
         else if (c == L'\b' || c == 127)
         {
@@ -226,7 +228,7 @@ const SearchPattern *CurseOutput::inputSearch()
         else
             buffer += c;
     }
-    wtimeout(stdscr, 150);
+    wtimeout(w, 150);
     curs_set(false);
 
     {
@@ -265,6 +267,7 @@ void CurseOutput::writeBottomLine(const std::string &buffer, short color) const
     move(screenSize.second -1, bufsize);
     if (params.colorEnabled())
         attroff(COLOR_PAIR(color));
+    refresh();
 }
 
 void CurseOutput::writeBottomLine(const std::wstring &buffer, short color) const
@@ -278,6 +281,7 @@ void CurseOutput::writeBottomLine(const std::wstring &buffer, short color) const
     move(screenSize.second -1, bufsize);
     if (params.colorEnabled())
         attroff(COLOR_PAIR(color));
+    refresh();
 }
 
 void CurseOutput::init()

+ 44 - 24
src/curseSplitOutput.cpp

@@ -16,9 +16,10 @@
 #include "jsonPrimitive.hh"
 #include "levenshteinMatrice.hpp"
 
-template<class T> const T &list_at(const std::list<T> &l, unsigned int pos)
+template<class T> static const T &list_at(const std::list<T> &l, unsigned int pos)
 {
     typename std::list<T>::const_iterator it = l.cbegin();
+
     std::advance(it, pos);
     return *it;
 }
@@ -46,6 +47,8 @@ void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::
     destroyAllSubWin();
     subWindows.clear();
     screenSize = getScreenSize(); // screenSize is based on nbInputs, we must refresh it
+    t_Cursor ss = getScreenSizeUnsafe();
+    bottomLine = newwin(1, ss.first, ss.second -1, 0);
 
     for (size_t i =0; i < nbInputs; ++i)
     {
@@ -90,23 +93,7 @@ inputResult CurseSplitOutput::selectUp()
 
 inputResult CurseSplitOutput::selectDown()
 {
-    const JSonElement *newSelection = subWindows.at(selectedWin).select_down;
-    size_t i = 0;
-
-    for (t_subWindow &w : subWindows)
-    {
-        if (w.selectIsLast)
-            w.scrollTop += 2;
-        if (i == selectedWin)
-            w.selection = w.lastSelection = newSelection;
-        else
-        {
-            w.selection = diffMatrice->getEquivalence(newSelection);
-            if (w.selection)
-                w.lastSelection = w.selection;
-        }
-        ++i;
-    }
+    setSelection(subWindows.at(selectedWin).select_down);
     return inputResult::redraw;
 }
 
@@ -211,7 +198,8 @@ inputResult CurseSplitOutput::collapseSelection()
 
 inputResult CurseSplitOutput::initSearch()
 {
-    const SearchPattern *searchPattern = inputSearch();
+    const SearchPattern *searchPattern = inputSearch(subWindows.at(0).outerWin);
+
     if (!searchPattern)
         return inputResult::redraw;
     for (t_subWindow &s : subWindows)
@@ -310,7 +298,7 @@ bool CurseSplitOutput::jumpToNextSearch(const JSonElement *current, bool &select
                 current != subWindows.at(selectedWin).selection &&
                 selectFound)
         {
-            subWindows.at(selectedWin).lastSelection = current;
+            setSelection(current);
             return true;
         }
         if (objEntry)
@@ -345,14 +333,14 @@ unsigned int CurseSplitOutput::search(const SearchPattern &searchPattern, const
         if (current && current->match(searchPattern))
         {
             if (current->getParent() && dynamic_cast<const JSonObjectEntry*>(current->getParent()))
-                subWindows.at(workingWin).searchResults.push_back(current->getParent());
+                subWindows.at(selectedWin).searchResults.push_back(current->getParent());
             else
-                subWindows.at(workingWin).searchResults.push_back(current);
+                subWindows.at(selectedWin).searchResults.push_back(current);
         }
         if (objEntry)
             search(searchPattern, **objEntry);
     }
-    return subWindows.at(workingWin).searchResults.size();
+    return subWindows.at(selectedWin).searchResults.size();
 }
 
 bool CurseSplitOutput::jumpToNextSearch()
@@ -362,7 +350,7 @@ bool CurseSplitOutput::jumpToNextSearch()
 
     if (!res)
     {
-        subWindows.at(selectedWin).lastSelection = *(subWindows.at(selectedWin).searchResults.cbegin());
+        setSelection(*(subWindows.at(selectedWin).searchResults.cbegin()));
         unfold(subWindows.at(selectedWin).selection);
         CurseOutput::redraw("Search hit BOTTOM, continuing at TOP");
         return false;
@@ -418,8 +406,11 @@ const Optional<bool> CurseSplitOutput::redrawOneItemToWorkingWin(t_subWindow &w)
 void CurseSplitOutput::onResizeHandler()
 {
     size_t i =0;
+    t_Cursor ss = getScreenSizeUnsafe();
     clear();
 
+    wresize(bottomLine, 1, ss.first);
+    mvwin(bottomLine, ss.second -1, 0);
     for (t_subWindow &subwin: subWindows)
     {
         wresize(subwin.outerWin, screenSize.second +2, screenSize.first);
@@ -556,6 +547,34 @@ bool CurseSplitOutput::writeContainer(JSonContainer *item, bool opening)
     return !hasReachedBottom(w.cursor.second, w.scrollTop, screenSize.second);
 }
 
+void CurseSplitOutput::writeBottomLine(const std::string &buffer, short color) const
+{
+    const t_Cursor screenSize = getScreenSizeUnsafe();
+    const size_t bufsize = buffer.size();
+
+    if (params.colorEnabled())
+        wattron(bottomLine, COLOR_PAIR(color));
+    mvwprintw(bottomLine, 0, 0, "%s%*c", buffer.c_str(), screenSize.first - bufsize, ' ');
+    wmove(bottomLine, 0, bufsize);
+    if (params.colorEnabled())
+        wattroff(bottomLine, COLOR_PAIR(color));
+    wrefresh(bottomLine);
+}
+
+void CurseSplitOutput::writeBottomLine(const std::wstring &buffer, short color) const
+{
+    const t_Cursor ss = getScreenSizeUnsafe();
+    const size_t bufsize = buffer.size();
+
+    if (params.colorEnabled())
+        wattron(bottomLine, COLOR_PAIR(color));
+    mvwprintw(bottomLine, 0, 0, "%S%*c", buffer.c_str(), ss.first - bufsize, ' ');
+    wmove(bottomLine, 0, bufsize);
+    if (params.colorEnabled())
+        wattroff(bottomLine, COLOR_PAIR(color));
+    wrefresh(bottomLine);
+}
+
 bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, OutputFlag flags, unsigned int extraLen)
 {
     if (w.cursor.second <= w.scrollTop)
@@ -827,6 +846,7 @@ const t_Cursor CurseSplitOutput::getScreenSize() const
 void CurseSplitOutput::shutdown()
 {
     destroyAllSubWin();
+    delwin(bottomLine);
     endwin();
     delscreen(screen);
     if (screen_fd)