From c9f71b0c6447c2068aadd8be31d6d14db79b906d Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 13 Feb 2019 11:59:34 +0100 Subject: [PATCH] add checks in curses ui for small windows addch() and addstr() throw an exception if text has to be printed outside of the window. This may occur if the terminal is very small. Such erroneous prints are no-ops now. Signed-off-by: Mart Lubbers Signed-off-by: Nicolas Sebrecht Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/595 --- offlineimap/ui/Curses.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/offlineimap/ui/Curses.py b/offlineimap/ui/Curses.py index ec06c04..89d0282 100644 --- a/offlineimap/ui/Curses.py +++ b/offlineimap/ui/Curses.py @@ -137,7 +137,13 @@ class CursesAccountFrame: sleepstr = '%3d:%02d'% (secs // 60, secs % 60) if secs else 'active' accstr = '%s: [%s] %12.12s: '% (self.acc_num, sleepstr, self.account) - self.ui.exec_locked(self.window.addstr, 0, 0, accstr) + def addstr(): + try: + self.window.addstr(0, 0, accstr) + except curses.error as e: # Occurs when the terminal is very small + pass + self.ui.exec_locked(addstr); + self.location = len(accstr) def setwindow(self, curses_win, acc_num): @@ -211,7 +217,10 @@ class CursesThreadFrame: def display(self): def locked_display(): - self.window.addch(self.y, self.x, '@', self.curses_color) + try: + self.window.addch(self.y, self.x, '@', self.curses_color) + except curses.error: # Occurs when the terminal is very small + pass self.window.refresh() # lock the curses IO while fudging stuff self.ui.exec_locked(locked_display)