diff --git a/src/osc_sender.py b/src/osc_sender.py index 8def04b..0d865c3 100644 --- a/src/osc_sender.py +++ b/src/osc_sender.py @@ -84,31 +84,36 @@ class OSCSender: print("No chords loaded!") return - try: - import threading - import tty - import termios - import os + import tty + import termios + import os - # Send and display first chord - self.send_chord(self.current_index) - self.display_chord(self.current_index) + # Send and display first chord + self.send_chord(self.current_index) + self.display_chord(self.current_index) - def get_key(): - """Get a single keypress.""" + def get_key(): + """Get a single keypress. Returns None on error.""" + try: fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) + return ch finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch + except (termios.error, OSError): + # Fallback for non-tty environments + return sys.stdin.read(1) if sys.stdin else None - print("\nUse arrow keys to navigate. Press Ctrl+C to quit.") + print("\nUse arrow keys to navigate. Press Ctrl+C to quit.") + try: while True: key = get_key() + if key is None: + break # Left arrow if key == "\x1b": # Escape sequence start @@ -140,6 +145,8 @@ class OSCSender: except KeyboardInterrupt: print("\n\nPlayback stopped.") + except Exception: + pass # Clean exit for any other error def send_all(self): """Send all chords in sequence (for testing)."""