def __init__(self):
super().__init__()
self.selfpipes = []
+ self.resized = False
def curses_setup(self):
self.scr = curses.initscr()
rfds_in.append(sp.rfd)
rfds_out, _, _ = select.select(rfds_in, [], [])
rfds_out = set(rfds_out)
+ resized = False
for (sp, handler, _) in self.selfpipes:
if sp.rfd in rfds_out and sp.check():
- handler()
+ if handler():
+ resized = True
+ if resized:
+ return None
if 0 in rfds_out:
return self.get_wch()
else:
def handler():
size = os.get_terminal_size()
curses.resizeterm(size.lines, size.columns)
- # This is the same way standard curses will do it, which
- # is as good a way as any to signal to the main loop that
- # we need to do something
- curses.unget_wch(curses.KEY_RESIZE)
+ # Signal to the main loop that we've been resized. If
+ # curses were doing this itself, we'd see KEY_RESIZE in
+ # our input stream, but apparently passing that to
+ # curses.unget_wch does the wrong thing, and instead we
+ # receive U+019A from get_wch. (0x19A is the numerical
+ # value of curses.KEY_RESIZE, so it seems reasonably
+ # obvious what manner of confusion has happened there.)
+ #
+ # So instead, we set a flag of our own and return True,
+ # which causes get_input() to return None, which causes
+ # the main loop to check the resize flag.
+ self.resized = True
+ return True
self.selfpipes.append((sp, handler, None))
def get_composer(self):
self.clear()
self.activity_stack[-1].render()
self.scr.refresh()
- ch = self.get_input()
+ while True:
+ ch = self.get_input()
+ if ch is not None:
+ break
+ if self.resized:
+ self.resized = False
+ ch = curses.KEY_RESIZE
+ break
if ch == ctrl('['):
if self.activity_stack[-1] is not self.escape_menu:
self.activity_stack.append(self.escape_menu)