Curses UI: make resize behave better
Resizing a Blinkenlights terminal doesn't crash anymore, and actually seems to be changing the size, with this patch. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
bfbd378025
commit
70125d58e6
@ -119,6 +119,7 @@ class CursesAccountFrame:
|
|||||||
self.children = []
|
self.children = []
|
||||||
self.accountname = accountname
|
self.accountname = accountname
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
|
self.window = None
|
||||||
|
|
||||||
def drawleadstr(self, secs = None):
|
def drawleadstr(self, secs = None):
|
||||||
#TODO: does what?
|
#TODO: does what?
|
||||||
@ -178,7 +179,7 @@ class CursesThreadFrame:
|
|||||||
self.curses_color = curses.color_pair(0) #default color
|
self.curses_color = curses.color_pair(0) #default color
|
||||||
|
|
||||||
def setcolor(self, color, modifier=0):
|
def setcolor(self, color, modifier=0):
|
||||||
"""Draw the thread symbol '.' in the specified color
|
"""Draw the thread symbol '@' in the specified color
|
||||||
:param modifier: Curses modified, such as curses.A_BOLD"""
|
:param modifier: Curses modified, such as curses.A_BOLD"""
|
||||||
self.curses_color = modifier | self.ui.curses_colorpair(color)
|
self.curses_color = modifier | self.ui.curses_colorpair(color)
|
||||||
self.colorname = color
|
self.colorname = color
|
||||||
@ -186,7 +187,7 @@ class CursesThreadFrame:
|
|||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
def locked_display():
|
def locked_display():
|
||||||
self.window.addch(self.y, self.x, '.', self.curses_color)
|
self.window.addch(self.y, self.x, '@', self.curses_color)
|
||||||
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)
|
||||||
@ -289,7 +290,7 @@ class CursesLogHandler(logging.StreamHandler):
|
|||||||
finally:
|
finally:
|
||||||
self.ui.unlock()
|
self.ui.unlock()
|
||||||
self.ui.tframe_lock.release()
|
self.ui.tframe_lock.release()
|
||||||
self.ui.logwin.refresh()
|
self.ui.logwin.noutrefresh()
|
||||||
self.ui.stdscr.refresh()
|
self.ui.stdscr.refresh()
|
||||||
|
|
||||||
class Blinkenlights(UIBase, CursesUtil):
|
class Blinkenlights(UIBase, CursesUtil):
|
||||||
@ -509,7 +510,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
|
|
||||||
def resizeterm(self):
|
def resizeterm(self):
|
||||||
"""Resize the current windows"""
|
"""Resize the current windows"""
|
||||||
self.exec_locked(self.setupwindows(True))
|
self.exec_locked(self.setupwindows, True)
|
||||||
|
|
||||||
def mainException(self):
|
def mainException(self):
|
||||||
UIBase.mainException(self)
|
UIBase.mainException(self)
|
||||||
@ -537,24 +538,21 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
|
|
||||||
If `resize`, don't create new windows, just adapt size"""
|
If `resize`, don't create new windows, just adapt size"""
|
||||||
self.height, self.width = self.stdscr.getmaxyx()
|
self.height, self.width = self.stdscr.getmaxyx()
|
||||||
if resize:
|
|
||||||
raise Exception("resizehandler %d" % self.width)
|
|
||||||
|
|
||||||
self.logheight = self.height - len(self.accframes) - 1
|
self.logheight = self.height - len(self.accframes) - 1
|
||||||
if resize:
|
if resize:
|
||||||
curses.resizeterm(self.height, self.width)
|
curses.resizeterm(self.height, self.width)
|
||||||
self.bannerwin.resize(1, self.width)
|
self.bannerwin.resize(1, self.width)
|
||||||
|
self.logwin.resize(self.logheight, self.width)
|
||||||
else:
|
else:
|
||||||
self.bannerwin = curses.newwin(1, self.width, 0, 0)
|
self.bannerwin = curses.newwin(1, self.width, 0, 0)
|
||||||
self.logwin = curses.newwin(self.logheight, self.width, 1, 0)
|
self.logwin = curses.newwin(self.logheight, self.width, 1, 0)
|
||||||
|
|
||||||
self.draw_bannerwin()
|
self.draw_bannerwin()
|
||||||
self.logwin.idlok(1)
|
self.logwin.idlok(True) # needed for scrollok below
|
||||||
self.logwin.scrollok(1)
|
self.logwin.scrollok(True) # scroll window when too many lines added
|
||||||
self.logwin.move(self.logheight - 1, 0)
|
self.logwin.move(self.logheight - 1, 0)
|
||||||
self.draw_logwin()
|
self.draw_logwin()
|
||||||
self.accounts = reversed(sorted(self.accframes.keys()))
|
self.accounts = reversed(sorted(self.accframes.keys()))
|
||||||
|
|
||||||
pos = self.height - 1
|
pos = self.height - 1
|
||||||
index = 0
|
index = 0
|
||||||
self.hotkeys = []
|
self.hotkeys = []
|
||||||
@ -572,6 +570,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
color = curses.A_BOLD | self.curses_colorpair('banner')
|
color = curses.A_BOLD | self.curses_colorpair('banner')
|
||||||
else:
|
else:
|
||||||
color = curses.A_REVERSE
|
color = curses.A_REVERSE
|
||||||
|
self.bannerwin.clear() # Delete old content (eg before resizes)
|
||||||
self.bannerwin.bkgd(' ', color) # Fill background with that color
|
self.bannerwin.bkgd(' ', color) # Fill background with that color
|
||||||
string = "%s %s" % (offlineimap.__productname__,
|
string = "%s %s" % (offlineimap.__productname__,
|
||||||
offlineimap.__version__)
|
offlineimap.__version__)
|
||||||
@ -581,10 +580,12 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
self.bannerwin.noutrefresh()
|
self.bannerwin.noutrefresh()
|
||||||
|
|
||||||
def draw_logwin(self):
|
def draw_logwin(self):
|
||||||
#if curses.has_colors():
|
"""(Re)draw the current logwindow"""
|
||||||
# color = s.c.getpair(curses.COLOR_WHITE, curses.COLOR_BLACK)
|
if curses.has_colors():
|
||||||
#else:
|
color = curses.color_pair(0) #default colors
|
||||||
|
else:
|
||||||
color = curses.A_NORMAL
|
color = curses.A_NORMAL
|
||||||
|
self.logwin.clear()
|
||||||
self.logwin.bkgd(' ', color)
|
self.logwin.bkgd(' ', color)
|
||||||
for line, color in self.text:
|
for line, color in self.text:
|
||||||
self.logwin.addstr("\n" + line, color)
|
self.logwin.addstr("\n" + line, color)
|
||||||
@ -598,7 +599,8 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
# 1) Return existing or 2) create a new CursesAccountFrame.
|
# 1) Return existing or 2) create a new CursesAccountFrame.
|
||||||
if acc_name in self.accframes: return self.accframes[acc_name]
|
if acc_name in self.accframes: return self.accframes[acc_name]
|
||||||
self.accframes[acc_name] = CursesAccountFrame(self, acc_name)
|
self.accframes[acc_name] = CursesAccountFrame(self, acc_name)
|
||||||
self.setupwindows()
|
# update the window layout
|
||||||
|
self.setupwindows(resize= True)
|
||||||
return self.accframes[acc_name]
|
return self.accframes[acc_name]
|
||||||
|
|
||||||
def terminate(self, *args, **kwargs):
|
def terminate(self, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user