[tor-commits] [nyx/master] Simpify torrc content height handling

atagar at torproject.org atagar at torproject.org
Sun Feb 14 02:55:49 UTC 2016


commit 439ac3d359f03588c486d3aad3be967a4f99fc8e
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Feb 7 21:56:58 2016 -0800

    Simpify torrc content height handling
    
    Determining our content's height is actually really tricky for panels with line
    wrapping such as this and the log. This panel had an attempt at optimization
    that really wasn't necessary so simplifying this.
---
 nyx/log_panel.py   |  2 +-
 nyx/torrc_panel.py | 32 +++++---------------------------
 2 files changed, 6 insertions(+), 28 deletions(-)

diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index e97d74b..258d7a7 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -278,7 +278,7 @@ class LogPanel(panel.Panel, threading.Thread):
     event_filter = self._filter.clone()
     event_types = list(self._event_types)
     scroll = int(self._scroll)
-    last_content_height = int(self._last_content_height)
+    last_content_height = self._last_content_height
     show_duplicates = self._show_duplicates
 
     is_scrollbar_visible = last_content_height > height - 1
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index 34b6c3a..769f09b 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -30,8 +30,7 @@ class TorrcPanel(panel.Panel):
     # height of the content when last rendered (the cached value is invalid if
     # _last_content_height_args is None or differs from the current dimensions)
 
-    self._last_content_height = 1
-    self._last_content_height_args = None
+    self._last_content_height = 0
 
     self._torrc_location = None
     self._torrc_content = None
@@ -73,7 +72,6 @@ class TorrcPanel(panel.Panel):
     """
 
     self._strip_comments = not is_visible
-    self._last_content_height_args = None
     self.redraw(True)
 
   def set_line_number_visible(self, is_visible):
@@ -85,7 +83,6 @@ class TorrcPanel(panel.Panel):
     """
 
     self._show_line_numbers = is_visible
-    self._last_content_height_args = None
     self.redraw(True)
 
   def handle_key(self, key):
@@ -105,12 +102,6 @@ class TorrcPanel(panel.Panel):
 
     return True
 
-  def set_visible(self, is_visible):
-    if not is_visible:
-      self._last_content_height_args = None  # redraws when next displayed
-
-    panel.Panel.set_visible(self, is_visible)
-
   def get_help(self):
     return [
       ('up arrow', 'scroll up a line', None),
@@ -131,14 +122,6 @@ class TorrcPanel(panel.Panel):
       self.addstr(1, 0, self._torrc_load_error, 'red', curses.A_BOLD)
       return
 
-    # If true, we assume that the cached value in self._last_content_height is
-    # still accurate, and stop drawing when there's nothing more to display.
-    # Otherwise the self._last_content_height is suspect, and we'll process all
-    # the content to check if it's right (and redraw again with the corrected
-    # height if not).
-
-    trust_last_content_height = self._last_content_height_args == (width, height)
-
     # restricts scroll location to valid bounds
 
     self._scroll = max(0, min(self._scroll, self._last_content_height - height + 1))
@@ -268,13 +251,8 @@ class TorrcPanel(panel.Panel):
 
       display_line += max(line_offset, 1)
 
-      if trust_last_content_height and display_line >= height:
-        break
-
-    if not trust_last_content_height:
-      self._last_content_height_args = (width, height)
-      new_content_height = display_line + self._scroll - 1
+    new_content_height = display_line + self._scroll - 1
 
-      if self._last_content_height != new_content_height:
-        self._last_content_height = new_content_height
-        self.redraw(True)
+    if self._last_content_height != new_content_height:
+      self._last_content_height = new_content_height
+      self.redraw(True)





More information about the tor-commits mailing list