Sfoglia il codice sorgente

[Fix] scrolling issue (scrolling if selection out-of-screen)

isundil 9 anni fa
parent
commit
c3609edc64
2 ha cambiato i file con 11 aggiunte e 8 eliminazioni
  1. 2 2
      doc/jsonstroll.1
  2. 9 6
      src/curseOutput.cpp

+ 2 - 2
doc/jsonstroll.1

@@ -1,7 +1,7 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.47.3.
-.TH JSONSTROLL "1" "August 2016" "jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  7 2016" "User Commands"
+.TH JSONSTROLL "1" "August 2016" "jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug 12 2016" "User Commands"
 .SH NAME
-jsonstroll \- manual page for jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  7 2016
+jsonstroll \- manual page for jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug 12 2016
 .SH SYNOPSIS
 .B jsonstroll
 [\fI\,OPTIONS\/\fR]

+ 9 - 6
src/curseOutput.cpp

@@ -19,7 +19,7 @@
 #include "except.hh"
 
 static CurseOutput *runningInst = nullptr;
-class SelectionOutOfRange {};
+class SelectionOutOfRange { };
 
 CurseOutput::CurseOutput(JSonElement *root, const Params &p): data(root), selection(root), params(p)
 { }
@@ -56,7 +56,7 @@ bool CurseOutput::onsig(int signo)
         if (ioctl(fileno(screen_fd ? screen_fd : stdout), TIOCGWINSZ, &size) == 0)
             resize_term(size.ws_row, size.ws_col);
         clear();
-        redraw();
+        while (!redraw());
         break;
 
     case SIGKILL:
@@ -82,6 +82,9 @@ bool CurseOutput::redraw()
 {
     const std::pair<unsigned int, unsigned int> screenSize = getScreenSize();
     std::pair<int, int> cursor(0, 0);
+    /**
+     * Will be true if the json's last item is visible
+    **/
     bool result;
 
     select_up = select_down = nullptr;
@@ -155,7 +158,7 @@ bool CurseOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<un
     {
         std::string ss;
         ss.append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
-        cursor.second += write(cursor.first, cursor.second, ss, maxSize.first, selection == item);
+        cursor.second += write(cursor.first, cursor.second, ss, maxSize.first, getFlag(item));
     }
     else
     {
@@ -189,7 +192,7 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
             {
                 if (dynamic_cast<const JSonObject *>(**ent))
                 {
-                    if (!writeKey(key, "{ ... }", cursor, maxSize, getFlag(ent)))
+                    if (!writeKey(key, "{ ... }", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
                         break;
                 }
                 else if (!writeKey(key, "[ ... ]", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
@@ -204,7 +207,7 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
             {
                 if (dynamic_cast<const JSonObject *>(**ent) )
                 {
-                    if (!writeKey(key, "{ }", cursor, maxSize, getFlag(ent)))
+                    if (!writeKey(key, "{ }", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
                         break;
                 }
                 else if (!writeKey(key, "[ ]", cursor, maxSize, getFlag(ent)) || (cursor.second - scrollTop > 0 && (unsigned)(cursor.second - scrollTop) > maxSize.second -1))
@@ -212,7 +215,7 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
             }
             else
             {
-                if (!writeKey(key, cursor, maxSize, selection == ent))
+                if (!writeKey(key, cursor, maxSize, getFlag(ent)))
                     break;
                 const JSonElement *saveSelection = selection;
                 if (selection == ent)