diff options
author | Helmut Grohne <helmut@subdivi.de> | 2013-06-02 15:36:11 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2013-06-02 15:36:11 +0200 |
commit | 70228ca2e5af1968f3b4d3277212008c15875980 (patch) | |
tree | 9a9498eff599ee080e653cf0266b7e3a3ac6a9b2 | |
parent | ccf38158e6e7fefd2b7bdbde243da98ffff79270 (diff) | |
download | tcvt-70228ca2e5af1968f3b4d3277212008c15875980.tar.gz |
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.
-rwxr-xr-x | tcvt.py | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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() |