]> code.delx.au - offlineimap/blobdiff - offlineimap/head/offlineimap/ui/Curses.py
/offlineimap/head: changeset 367
[offlineimap] / offlineimap / head / offlineimap / ui / Curses.py
index 360787b256b25ed0bc11c835e8f497bcc7caa58b..52f8f11e477ee4d3952991fc27d05fca84cb2b09 100644 (file)
@@ -4,7 +4,8 @@
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; version 2 of the License.
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,7 +19,7 @@
 from Blinkenlights import BlinkenBase
 from UIBase import UIBase
 from threading import *
-import thread, time, sys, os
+import thread, time, sys, os, signal, time
 from offlineimap import version, threadutil
 from offlineimap.threadutil import MultiLock
 
@@ -318,6 +319,32 @@ class Blinkenlights(BlinkenBase, UIBase):
         s.gettf().setcolor('red')
         s._msg(version.banner)
         s.inputhandler.set_bgchar(s.keypress)
+        signal.signal(signal.SIGWINCH, s.resizehandler)
+        s.resizelock = Lock()
+        s.resizecount = 0
+
+    def resizehandler(s, signum, frame):
+        s.resizeterm()
+
+    def resizeterm(s, dosleep = 1):
+        if not s.resizelock.acquire(0):
+            s.resizecount += 1
+            return
+        signal.signal(signal.SIGWINCH, signal.SIG_IGN)
+        s.aflock.acquire()
+        s.c.lock()
+        s.resizecount += 1
+        while s.resizecount:
+            s.c.reset()
+            s.setupwindows()
+            s.resizecount -= 1
+        s.c.unlock()
+        s.aflock.release()
+        s.resizelock.release()
+        signal.signal(signal.SIGWINCH, s.resizehandler)
+        if dosleep:
+            time.sleep(1)
+            s.resizeterm(0)
 
     def isusable(s):
         # Not a terminal?  Can't use curses.