Fix cf arrow key handling - remove broken select() logic

The select() timeout approach was causing arrow keys to be
misinterpreted as Escape. Revert to direct reading since escape
sequence bytes arrive together from the terminal.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
rob
2026-01-18 04:52:47 -04:00
co-authored by Claude Opus 4.5
parent d230cffb5f
commit cb6a8df79b
+8 -12
View File
@@ -4,7 +4,6 @@ import sys
import os
import tty
import termios
import select
from typing import List, Tuple, Optional
from dataclasses import dataclass
@@ -110,17 +109,14 @@ class TTYInput:
try:
ch = self.tty.read(1)
if ch == '\x1b':
# Use select to check if more chars available (escape sequence)
# Timeout of 0.05s - if nothing comes, it was just Escape
if select.select([self.fd], [], [], 0.05)[0]:
ch2 = self.tty.read(1)
if ch2 == '[':
if select.select([self.fd], [], [], 0.05)[0]:
ch3 = self.tty.read(1)
if ch3 == 'A': return 'UP'
if ch3 == 'B': return 'DOWN'
if ch3 == 'C': return 'RIGHT'
if ch3 == 'D': return 'LEFT'
# Read escape sequence - bytes arrive together from terminal
ch2 = self.tty.read(1)
if ch2 == '[':
ch3 = self.tty.read(1)
if ch3 == 'A': return 'UP'
if ch3 == 'B': return 'DOWN'
if ch3 == 'C': return 'RIGHT'
if ch3 == 'D': return 'LEFT'
return ch
finally:
termios.tcsetattr(self.fd, termios.TCSANOW, self.old_settings)