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 <mart@martlubbers.net>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/595
This commit is contained in:
Mart Lubbers 2019-02-13 11:59:34 +01:00 committed by Nicolas Sebrecht
parent 137130fbd0
commit c9f71b0c64

View File

@ -137,7 +137,13 @@ class CursesAccountFrame:
sleepstr = '%3d:%02d'% (secs // 60, secs % 60) if secs else 'active' sleepstr = '%3d:%02d'% (secs // 60, secs % 60) if secs else 'active'
accstr = '%s: [%s] %12.12s: '% (self.acc_num, sleepstr, self.account) 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) self.location = len(accstr)
def setwindow(self, curses_win, acc_num): def setwindow(self, curses_win, acc_num):
@ -211,7 +217,10 @@ class CursesThreadFrame:
def display(self): def display(self):
def locked_display(): def locked_display():
try:
self.window.addch(self.y, self.x, '@', self.curses_color) self.window.addch(self.y, self.x, '@', self.curses_color)
except curses.error: # Occurs when the terminal is very small
pass
self.window.refresh() self.window.refresh()
# lock the curses IO while fudging stuff # lock the curses IO while fudging stuff
self.ui.exec_locked(locked_display) self.ui.exec_locked(locked_display)