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 <noreply@anthropic.com>
This commit is contained in:
rob 2026-01-18 04:52:47 -04:00
parent d230cffb5f
commit cb6a8df79b
1 changed files with 8 additions and 12 deletions

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,12 +109,9 @@ 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]:
# Read escape sequence - bytes arrive together from terminal
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'