[tor-commits] [nyx/master] Menu popups stacktrace if unable to be rendered

atagar at torproject.org atagar at torproject.org
Mon Jan 4 17:43:05 UTC 2016


commit bfe84b3372061bb2040dc1b7ec87777ebfb14386
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Dec 12 15:20:10 2015 -0800

    Menu popups stacktrace if unable to be rendered
    
    We returned an undefined 'selection' if the popup couldn't be made.
---
 nyx/popups.py |   60 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/nyx/popups.py b/nyx/popups.py
index d2d5ded..0e46ba6 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -390,43 +390,45 @@ def show_menu(title, options, old_selection):
   max_width = max(map(len, options)) + 9
 
   with popup_window(len(options) + 2, max_width) as (popup, _, _):
-    if popup:
-      selection = old_selection if old_selection != -1 else 0
+    if not popup:
+      return -1
 
-      # hides the title of the first panel on the page
+    selection = old_selection if old_selection != -1 else 0
 
-      control = nyx.controller.get_controller()
-      top_panel = control.get_display_panels(include_sticky = False)[0]
-      top_panel.set_title_visible(False)
-      top_panel.redraw(True)
+    # hides the title of the first panel on the page
 
-      curses.cbreak()   # wait indefinitely for key presses (no timeout)
+    control = nyx.controller.get_controller()
+    top_panel = control.get_display_panels(include_sticky = False)[0]
+    top_panel.set_title_visible(False)
+    top_panel.redraw(True)
 
-      while True:
-        popup.win.erase()
-        popup.win.box()
-        popup.addstr(0, 0, title, curses.A_STANDOUT)
+    curses.cbreak()   # wait indefinitely for key presses (no timeout)
 
-        for i in range(len(options)):
-          label = options[i]
-          format = curses.A_STANDOUT if i == selection else curses.A_NORMAL
-          tab = '> ' if i == old_selection else '  '
-          popup.addstr(i + 1, 2, tab)
-          popup.addstr(i + 1, 4, ' %s ' % label, format)
+    while True:
+      popup.win.erase()
+      popup.win.box()
+      popup.addstr(0, 0, title, curses.A_STANDOUT)
 
-        popup.win.refresh()
+      for i in range(len(options)):
+        label = options[i]
+        format = curses.A_STANDOUT if i == selection else curses.A_NORMAL
+        tab = '> ' if i == old_selection else '  '
+        popup.addstr(i + 1, 2, tab)
+        popup.addstr(i + 1, 4, ' %s ' % label, format)
 
-        key = control.key_input()
+      popup.win.refresh()
 
-        if key.match('up'):
-          selection = max(0, selection - 1)
-        elif key.match('down'):
-          selection = min(len(options) - 1, selection + 1)
-        elif key.is_selection():
-          break
-        elif key.match('esc'):
-          selection = -1
-          break
+      key = control.key_input()
+
+      if key.match('up'):
+        selection = max(0, selection - 1)
+      elif key.match('down'):
+        selection = min(len(options) - 1, selection + 1)
+      elif key.is_selection():
+        break
+      elif key.match('esc'):
+        selection = -1
+        break
 
   top_panel.set_title_visible(True)
   return selection





More information about the tor-commits mailing list