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:
parent
d230cffb5f
commit
cb6a8df79b
|
|
@ -4,7 +4,6 @@ import sys
|
||||||
import os
|
import os
|
||||||
import tty
|
import tty
|
||||||
import termios
|
import termios
|
||||||
import select
|
|
||||||
from typing import List, Tuple, Optional
|
from typing import List, Tuple, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
@ -110,17 +109,14 @@ class TTYInput:
|
||||||
try:
|
try:
|
||||||
ch = self.tty.read(1)
|
ch = self.tty.read(1)
|
||||||
if ch == '\x1b':
|
if ch == '\x1b':
|
||||||
# Use select to check if more chars available (escape sequence)
|
# Read escape sequence - bytes arrive together from terminal
|
||||||
# Timeout of 0.05s - if nothing comes, it was just Escape
|
ch2 = self.tty.read(1)
|
||||||
if select.select([self.fd], [], [], 0.05)[0]:
|
if ch2 == '[':
|
||||||
ch2 = self.tty.read(1)
|
ch3 = self.tty.read(1)
|
||||||
if ch2 == '[':
|
if ch3 == 'A': return 'UP'
|
||||||
if select.select([self.fd], [], [], 0.05)[0]:
|
if ch3 == 'B': return 'DOWN'
|
||||||
ch3 = self.tty.read(1)
|
if ch3 == 'C': return 'RIGHT'
|
||||||
if ch3 == 'A': return 'UP'
|
if ch3 == 'D': return 'LEFT'
|
||||||
if ch3 == 'B': return 'DOWN'
|
|
||||||
if ch3 == 'C': return 'RIGHT'
|
|
||||||
if ch3 == 'D': return 'LEFT'
|
|
||||||
return ch
|
return ch
|
||||||
finally:
|
finally:
|
||||||
termios.tcsetattr(self.fd, termios.TCSANOW, self.old_settings)
|
termios.tcsetattr(self.fd, termios.TCSANOW, self.old_settings)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue