Commit 55daf9d4 authored by louiz’'s avatar louiz’

Make the resize work, using an ugly workaround

It seems efficient (more than the curses.endwin(); stdscr.refresh() stuf,
which is slow and really really ugly) and it doesn't break my lovely main
loop, so it’s all good (except that it uses shutil…)
parent 0da96785
......@@ -11,6 +11,7 @@ log = logging.getLogger(__name__)
import asyncio
import collections
import shutil
import curses
import os
import pipes
......@@ -482,6 +483,27 @@ class Core(object):
sys.__excepthook__(typ, value, trace)
def sigwinch_handler(self):
"""A work-around for ncurses resize stuff, which sucks. Normally, ncurses
catches SIGWINCH itself. In its signal handler, it updates the
windows structures (for example the size, etc) and it
ungetch(KEY_RESIZE). That way, the next time we call getch() we know
that a resize occured and we can act on it. BUT poezio doesn’t call
getch() until it knows it will return something. The problem is we
can’t know that, because stdin is not affected by this KEY_RESIZE
value (it is only inserted in a ncurses internal fifo that we can’t
The (ugly) solution is to handle SIGWINCH ourself, trigger the
change of the internal windows sizes stored in ncurses module, using
sizes that we get using shutil, ungetch the KEY_RESIZE value and
then call getch to handle the resize on poezio’s side properly.
size = shutil.get_terminal_size()
curses.resizeterm(size.lines, size.columns)
def on_input_readable(self):
main loop waiting for the user to press a key
......@@ -562,8 +584,8 @@ class Core(object):
self.do_command(replace_line_breaks(char), False)
self.do_command(''.join(char_list), True)
def save_config(self):
......@@ -61,7 +61,9 @@ def main():
# the asyncio logger will not follow our configuration and won't write
# the tracebacks in the correct file, etc
import asyncio
asyncio.get_event_loop().add_reader(sys.stdin, cocore.on_input_readable)
asyncio.get_event_loop().add_signal_handler(signal.SIGWINCH, cocore.sigwinch_handler)
# We reach this point only when loop.stop() is called
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment