Fix input_box refresh() out of order resize
authorJack Miller <jack@codezen.org>
Wed, 28 Jun 2017 05:29:21 +0000 (00:29 -0500)
committerJack Miller <jack@codezen.org>
Wed, 28 Jun 2017 06:16:12 +0000 (01:16 -0500)
Because readline is in charge of calling redisplay, and appears to call
redisplay on resize, and redisplay call input_box.refresh, which is
racing with potentially initing a new input_box, so if the input box's
init() hasn't been called yet, don't do anything.

Fixes exceptions when resizing frequently with a prompt open.

canto_curses/input.py
canto_curses/screen.py

index 215f354..b2e7397 100644 (file)
@@ -26,6 +26,7 @@ class InputBox(GuiBase):
     def __init__(self):
         GuiBase.__init__(self)
         self.plugin_class = InputPlugin
+        self.pad = None
 
     def init(self, pad, callbacks):
         self.pad = pad
@@ -79,6 +80,9 @@ class InputBox(GuiBase):
         return None
 
     def refresh(self):
+        if not self.pad:
+            return
+
         self.pad.move(0, self.minx)
         maxx = self.pad.getmaxyx()[1]
 
@@ -95,7 +99,10 @@ class InputBox(GuiBase):
         self.x = self.pad.getyx()[1]
         self.pad.clrtoeol()
         self.pad.move(0, min(maxx - 1, self.minx + get_rlpoint()))
-        self.callbacks["refresh"]()
+        try:
+            self.callbacks["refresh"]()
+        except:
+            pass
 
     def redraw(self):
         pass
index 5db9980..174e0c7 100644 (file)
@@ -653,8 +653,9 @@ Arguments:"""),
 
         if r == curses.KEY_BACKSPACE:
             r = ord("\b")
-
-        if chr(r) == '\t' and do_comp:
+        elif r == curses.KEY_RESIZE:
+            return
+        elif chr(r) == '\t' and do_comp:
             self.input_box.rotate_completions()
             return