From 70228ca2e5af1968f3b4d3277212008c15875980 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 2 Jun 2013 15:36:11 +0200 Subject: fix WINCH handling * The switch to single column on WINCH was a bad idea. * The new window would get old dimensions, because we would reinitialize windows before curses noticed the new dimensions. --- tcvt.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tcvt.py b/tcvt.py index 4393cfb..9252bad 100755 --- a/tcvt.py +++ b/tcvt.py @@ -111,14 +111,19 @@ class Simple: def inch(self): return self.screen.inch() +class BadWidth(Exception): + pass + class Columns: def __init__(self, curseswindow, numcolumns=2): self.screen = curseswindow self.height, width = self.screen.getmaxyx() - assert numcolumns > 1 + if numcolumns < 1: + raise BadWidth("need at least two columns") self.numcolumns = numcolumns self.columnwidth = (width - (numcolumns - 1)) // numcolumns - assert self.columnwidth > 0 + if self.columnwidth <= 0: + raise BadWidth("resulting column width too small") self.windows = [] for i in range(numcolumns): window = self.screen.derwin(self.height, self.columnwidth, @@ -311,8 +316,12 @@ class Terminal: self.screen.refresh() def resized(self): - self.screen = Simple(self.realscreen) + # The refresh call causes curses to notice the new dimensions. self.screen.refresh() + try: + self.screen = Columns(self.realscreen, self.columns) + except BadWidth: + self.screen = Simple(self.realscreen) def resizepty(self, ptyfd): ym, xm = self.screen.getmaxyx() -- cgit v1.2.3