fix: Disable key debounce for text input entry and typing

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-03-04 17:03:58 -07:00
parent c58a356c02
commit 17e3ad347a
2 changed files with 28 additions and 2 deletions

View File

@@ -45,13 +45,14 @@ def main_loop(stdscr):
while True: while True:
c = stdscr.getch() c = stdscr.getch()
if c != curses.ERR: if c != curses.ERR:
current_screen = screens[state.current_screen]
# Rate limit key presses unless in a text input field # Rate limit key presses unless in a text input field
if not screens[state.current_screen].is_typing and time.time() < state.last_key_time + 1: if not current_screen.is_typing and not current_screen.is_entry_key(c) and time.time() < state.last_key_time + 1:
pass # Key press ignored due to rate limit pass # Key press ignored due to rate limit
else: else:
state.c = c state.c = c
state.last_key_time = time.time() state.last_key_time = time.time()
screens[state.current_screen].handle_input(c) current_screen.handle_input(c)
if state.current_screen != state.prev_screen: if state.current_screen != state.prev_screen:
logging.info('Switching to screen: %s', state.current_screen) logging.info('Switching to screen: %s', state.current_screen)

25
tui.py
View File

@@ -44,6 +44,9 @@ class Screen:
except: except:
return None return None
def is_entry_key(self, c):
return False
def try_highlight(self, c): def try_highlight(self, c):
if c and time.time() - self.state.highlight_debounce > 0.6: if c and time.time() - self.state.highlight_debounce > 0.6:
self.state.highlight_debounce = time.time() self.state.highlight_debounce = time.time()
@@ -394,6 +397,10 @@ class SignScreen(Screen):
self.sign_to_send = '_' self.sign_to_send = '_'
else: self.try_highlight(c) else: self.try_highlight(c)
def is_entry_key(self, c):
button = self.get_button(c)
return not self.is_typing and button == 'e'
class ProtovacSignScreen(Screen): class ProtovacSignScreen(Screen):
def draw(self): def draw(self):
self.stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER') self.stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER')
@@ -541,6 +548,10 @@ class NametagScreen(Screen):
elif button == 'g': self.nametag_guest = '_' elif button == 'g': self.nametag_guest = '_'
else: self.try_highlight(c) else: self.try_highlight(c)
def is_entry_key(self, c):
button = self.get_button(c)
return not (self.nametag_member or self.nametag_guest) and button in ['m', 'g']
class LabelScreen(Screen): class LabelScreen(Screen):
# This screen is complex, breaking it down into sub-states # This screen is complex, breaking it down into sub-states
def __init__(self, state, stdscr): def __init__(self, state, stdscr):
@@ -688,6 +699,12 @@ class LabelScreen(Screen):
else: self.try_highlight(c) else: self.try_highlight(c)
else: self.try_highlight(c) else: self.try_highlight(c)
def is_entry_key(self, c):
if self.sub_screen == 'menu':
button = self.get_button(c)
return button in ['t', 's', 'g', 'c', 'f']
return False
class GamesScreen(Screen): class GamesScreen(Screen):
def draw(self): def draw(self):
@@ -785,6 +802,10 @@ I will be terse in my responses.''')]
elif button == 'e': self.is_typing = True; self.message_to_send = '_' elif button == 'e': self.is_typing = True; self.message_to_send = '_'
else: self.try_highlight(c) else: self.try_highlight(c)
def is_entry_key(self, c):
button = self.get_button(c)
return not self.is_typing and button == 'e'
class ThinkScreen(Screen): class ThinkScreen(Screen):
def __init__(self, state, stdscr): def __init__(self, state, stdscr):
@@ -855,6 +876,10 @@ class ThinkScreen(Screen):
elif button == 'e': self.is_typing = True; self.think_to_send = '_' elif button == 'e': self.is_typing = True; self.think_to_send = '_'
else: self.try_highlight(c) else: self.try_highlight(c)
def is_entry_key(self, c):
button = self.get_button(c)
return not self.is_typing and button == 'e'
class AboutScreen(Screen): class AboutScreen(Screen):
def draw(self): def draw(self):
self.stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER') self.stdscr.addstr(0, 1, 'PROTOVAC UNIVERSAL COMPUTER')