chiark / gitweb /
Do SIGWINCH handling ourselves.
authorSimon Tatham <anakin@pobox.com>
Wed, 6 Dec 2023 06:52:06 +0000 (06:52 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 6 Dec 2023 06:52:06 +0000 (06:52 +0000)
It broke as a side effect of going into nodelay mode, I think because
our select loop didn't know to check curses's flag.

cursesclient.py

index abf383b88e424f8bf42b582bd823938d8320156f..564a7a0aed7bf91f81879516d503f3f3e0125771 100644 (file)
@@ -1,6 +1,8 @@
 import curses
 import itertools
+import os
 import select
+import signal
 import sys
 import threading
 
@@ -112,7 +114,7 @@ class CursesUI(client.Client):
         else:
             return None
 
-    def add_selfpipe(self, url, handler):
+    def add_streaming_selfpipe(self, url, handler):
         sp = util.SelfPipe()
         gen = self.get_streaming_lines(url)
         def threadfn():
@@ -124,9 +126,22 @@ class CursesUI(client.Client):
         th.start()
         self.selfpipes.append((sp, handler, th))
 
+    def add_sigwinch_selfpipe(self):
+        sp = util.SelfPipe()
+        signal.signal(signal.SIGWINCH, lambda *args: sp.signal())
+        def handler():
+            size = os.get_terminal_size()
+            curses.resizeterm(size.lines, size.columns)
+            # This is the same way standard curses will do it, which
+            # is as good a way as any to signal to the main loop that
+            # we need to do something
+            curses.ungetch(curses.KEY_RESIZE)
+        self.selfpipes.append((sp, handler, None))
+
     def run(self):
         home_feed = self.home_timeline_feed()
-        self.add_selfpipe("streaming/user", home_feed.extend_future)
+        self.add_streaming_selfpipe("streaming/user", home_feed.extend_future)
+        self.add_sigwinch_selfpipe()
         self.home_timeline = StatusFile(
             self, home_feed,
             text.ColouredString("Home timeline   <H>",