Skip to content

Commit

Permalink
Fix losing symbolic keys after resize (no input)
Browse files Browse the repository at this point in the history
self.input_box almost always exists, so the previous patch didn't do
what I thought it did. Instead, use a proper flag. Try to do better with
resizes while in readline too.
  • Loading branch information
themoken committed Jun 28, 2017
1 parent 0fabf8e commit 6e1ba1d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions canto_curses/screen.py
Expand Up @@ -58,6 +58,9 @@ def __init__(self, callbacks, types = [InputBox, TagList]):
self.window_types = types

self.input_box = None
self.pseudo_input_box = None
self.in_readline = False
self.in_readline_resize = False

self.stdscr = curses.initscr()
if self.curses_setup() < 0:
Expand Down Expand Up @@ -170,11 +173,15 @@ def curs_set(self, n):
# endwin() (i.e. resize).

def curses_setup(self):
if not self.input_box:
if self.in_readline:
self.pseudo_input_box.keypad(0)
self.curs_set(1)
elif self.pseudo_input_box:
self.pseudo_input_box.nodelay(1)
self.pseudo_input_box.keypad(1)
self.curs_set(0)
else:
self.curs_set(1)
self.pseudo_input_box.keypad(0)
self.curs_set(0)

try:
curses.cbreak()
Expand Down Expand Up @@ -562,7 +569,14 @@ def input_callback(self, prompt, completions=True):

self.pseudo_input_box.keypad(0)

self.in_readline = True
r = raw_readline()
self.in_readline = False

if self.in_readline_resize:
self.in_readline_resize = False
self.resize()

if not r:
r = ""

Expand Down Expand Up @@ -660,6 +674,7 @@ def _readline_getc(self):
if r == curses.KEY_BACKSPACE:
r = ord("\b")
elif r == curses.KEY_RESIZE:
self.in_readline_resize = True
return
elif chr(r) == '\t' and do_comp:
self.input_box.rotate_completions()
Expand Down

0 comments on commit 6e1ba1d

Please sign in to comment.