[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Added scrollbar



commit 15f1e043c8c758db55e4b6bab1f1f4f25fd6a30f
Author: Sambuddha Basu <sambuddhabasu1@xxxxxxxxx>
Date:   Sat Jun 25 15:32:01 2016 -0700

    Added scrollbar
---
 nyx/panel/interpreter.py | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index bc5da76..7865c55 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -43,6 +43,8 @@ class InterpreterPanel(panel.Panel):
     panel.Panel.__init__(self, 'interpreter')
 
     self._is_input_mode = False
+    self._x_offset = 0
+    self._scroller = nyx.curses.Scroller()
     self.controller = stem.connection.connect(
       control_port = ('127.0.0.1', 'default'),
       control_socket = '/var/run/tor/control',
@@ -51,12 +53,20 @@ class InterpreterPanel(panel.Panel):
     self.interpreter = stem.interpreter.commands.ControlInterpretor(self.controller)
 
   def key_handlers(self):
+    def _scroll(key):
+      page_height = self.get_preferred_size()[0]
+      is_changed = self._scroller.handle_key(key, len(PROMPT_LINE), page_height)
+
+      if is_changed:
+        self.redraw(True)
+
     def _execute_command():
       self._is_input_mode = True
 
       while self._is_input_mode:
         self.redraw(True)
-        user_input = nyx.curses.str_input(len(PROMPT), self.top + len(PROMPT_LINE))
+        page_height = self.get_preferred_size()[0] - 1
+        user_input = nyx.curses.str_input(len(PROMPT) + self._x_offset, self.top + len(PROMPT_LINE[-page_height:]))
         user_input, is_done = user_input.strip(), False
 
         if not user_input:
@@ -77,16 +87,22 @@ class InterpreterPanel(panel.Panel):
 
     return (
       nyx.panel.KeyHandler('enter', 'execute a command', _execute_command, key_func = lambda key: key.is_selection()),
+      nyx.panel.KeyHandler('arrows', 'scroll up and down', _scroll, key_func = lambda key: key.is_scroll()),
     )
 
   def draw(self, width, height):
+    scroll = self._scroller.location(len(PROMPT_LINE), height)
+
     usage_msg = ' (enter \"/help\" for usage or a blank line to stop)' if self._is_input_mode else ""
     self.addstr(0, 0, 'Control Interpreter%s:' % usage_msg, HIGHLIGHT)
 
-    x_offset = 0
-    draw_line = 1
+    is_scrollbar_visible = len(PROMPT_LINE) > height - 1
+    if is_scrollbar_visible:
+      self.add_scroll_bar(scroll, scroll + height, len(PROMPT_LINE), 1)
+
+    self._x_offset, draw_line = 2 if is_scrollbar_visible else 0, 1 - scroll
     for entry in PROMPT_LINE:
-      cursor = x_offset
+      cursor = self._x_offset
 
       for line in entry:
         if len(line) == 1:



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits