From 4563ff8664059e4577a88ed493e40c6870903761 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 6 Dec 2023 06:28:28 +0000 Subject: [PATCH] Set curses nodelay mode. 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cursesclient.py b/cursesclient.py index e046ceb..abf383b 100644 --- a/cursesclient.py +++ b/cursesclient.py @@ -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) -- 2.30.2