Tab completion fixes.

This commit is contained in:
Storm Dragon
2026-05-12 17:39:56 -04:00
parent b599a25945
commit 96c5184450
7 changed files with 234 additions and 6 deletions
@@ -48,7 +48,7 @@ class command:
for curr_key in self.env["input"]["curr_input"]:
if curr_key not in filter_list:
return
self.env["runtime"]["OutputManager"].interrupt_output()
self.env["runtime"]["OutputManager"].interrupt_output_async()
def set_callback(self, callback):
pass
@@ -163,6 +163,14 @@ class InputManager:
def get_last_event(self):
return self.lastEvent
def record_unmanaged_keypress(self, event_name):
self.lastEvent = {
"event_name": event_name,
"event_state": 1,
}
self.set_last_deepest_input([event_name])
self.lastInputTime = time.time()
def handle_input_event(self, event_data):
if not event_data:
return
+40 -1
View File
@@ -6,6 +6,7 @@
import re
import string
import threading
import time
from fenrirscreenreader.core import debug
@@ -16,6 +17,11 @@ from fenrirscreenreader.utils import line_utils
class OutputManager:
def __init__(self):
self.last_echo = ""
self.interrupt_lock = threading.Lock()
self.interrupt_running = False
self.interrupt_thread = None
self.interrupt_done = None
self.interrupt_wait_timeout = 0.1
def initialize(self, environment):
self.env = environment
@@ -280,7 +286,40 @@ class OutputManager:
str(e), debug.DebugLevel.ERROR
)
def interrupt_output(self):
def interrupt_output(self, wait=True):
interrupt_done, started = self.start_interrupt_output()
if wait and started and interrupt_done:
interrupt_done.wait(timeout=self.interrupt_wait_timeout)
def interrupt_output_async(self):
self.start_interrupt_output()
def start_interrupt_output(self):
with self.interrupt_lock:
if self.interrupt_running:
return self.interrupt_done, False
self.interrupt_running = True
self.interrupt_done = threading.Event()
self.interrupt_thread = threading.Thread(
target=self.run_interrupt_output,
args=(self.interrupt_done,),
daemon=True,
)
interrupt_thread = self.interrupt_thread
interrupt_done = self.interrupt_done
interrupt_thread.start()
return interrupt_done, True
def run_interrupt_output(self, interrupt_done):
try:
self.cancel_speech()
finally:
interrupt_done.set()
with self.interrupt_lock:
if self.interrupt_done is interrupt_done:
self.interrupt_running = False
def cancel_speech(self):
try:
self.env["runtime"]["SpeechDriver"].cancel()
self.env["runtime"]["DebugManager"].write_debug_out(
@@ -333,9 +333,23 @@ class driver(screenDriver):
def handle_stdin_input(self, msg_bytes, event_queue):
if self.synthesize_backspace_shortcut(msg_bytes, event_queue):
return
self.record_stdin_keypress(msg_bytes)
self.interrupt_output_on_stdin_input(msg_bytes)
self.inject_text_to_screen(msg_bytes)
def record_stdin_keypress(self, msg_bytes):
if msg_bytes != b"\t":
return
try:
self.env["runtime"]["InputManager"].record_unmanaged_keypress(
"KEY_TAB"
)
except Exception as e:
self.env["runtime"]["DebugManager"].write_debug_out(
"ptyDriver record_stdin_keypress: " + str(e),
debug.DebugLevel.ERROR,
)
def synthesize_backspace_shortcut(self, msg_bytes, event_queue):
if msg_bytes not in [b"\x7f", b"\x08"]:
return False