chiark / gitweb /
Set curses nodelay mode.
authorSimon Tatham <anakin@pobox.com>
Wed, 6 Dec 2023 06:28:28 +0000 (06:28 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 6 Dec 2023 06:28:28 +0000 (06:28 +0000)
Otherwise, pressing M-g (in pterm, which curses will interpret as ESC
g, just as I'd want it to) delivers the ESC, but leaves the g in
curses's internal buffer, which we don't empty before diving back into
the select loop.

cursesclient.py

index e046ceb82c8d73d34551da2939c0027d4307fdd2..abf383b88e424f8bf42b582bd823938d8320156f 100644 (file)
@@ -41,6 +41,7 @@ class CursesUI(client.Client):
 
         self.scr.keypad(1)
         self.scr.scrollok(1)
+        self.scr.nodelay(1) # so we can use getch() via a select loop
         curses.noecho()
         self.scr_h, self.scr_w = self.scr.getmaxyx()
 
@@ -91,6 +92,13 @@ class CursesUI(client.Client):
             self.print_at(y, 0, text.ColouredString(' ' * self.scr_w))
 
     def get_input(self):
+        # There might be keystrokes still in curses's buffer from a
+        # previous read from stdin, so deal with those before we go
+        # back to the select loop
+        ch = self.scr.getch()
+        if ch != curses.ERR:
+            return ch
+
         rfds_in = [0]
         for (sp, handler, _) in self.selfpipes:
             rfds_in.append(sp.rfd)