Fix DECCKM support for arrow keys in TUI apps (mc, vim, htop)
- mc/vim/htop enable Application Cursor Mode (DECCKM ?1h) which requires arrow keys to send \eOA..D instead of \e[A..D - Detect DECCKM in pyte screen mode and send correct sequences - Fix thread-safety: use queue.Queue for SSH→main thread data transfer Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,10 @@ _DEFAULT_BG = "#1a1a2e"
|
||||
_CURSOR_FG = "#1a1a2e"
|
||||
_CURSOR_BG = "#d3d7cf"
|
||||
|
||||
# Key → VT100 escape sequence
|
||||
# DECCKM (private mode ?1) — pyte stores private modes shifted by 5 bits
|
||||
_DECCKM = 32
|
||||
|
||||
# Key → VT100 escape sequence (normal cursor mode)
|
||||
_KEY_MAP = {
|
||||
"Up": "\x1b[A",
|
||||
"Down": "\x1b[B",
|
||||
@@ -59,6 +62,16 @@ _KEY_MAP = {
|
||||
"F12": "\x1b[24~",
|
||||
}
|
||||
|
||||
# Application cursor mode (DECCKM) — mc, htop, vim enable this
|
||||
_KEY_MAP_APP_CURSOR = {
|
||||
"Up": "\x1bOA",
|
||||
"Down": "\x1bOB",
|
||||
"Right": "\x1bOC",
|
||||
"Left": "\x1bOD",
|
||||
"Home": "\x1bOH",
|
||||
"End": "\x1bOF",
|
||||
}
|
||||
|
||||
|
||||
class TerminalWidget(tk.Frame):
|
||||
"""VT100 terminal emulator widget using pyte + tkinter.Text."""
|
||||
@@ -301,9 +314,13 @@ class TerminalWidget(tk.Frame):
|
||||
self._send(bytes([ord(ch) - ord("a") + 1]))
|
||||
return "break"
|
||||
|
||||
# Special keys
|
||||
# Special keys — check DECCKM (application cursor mode) for arrow keys
|
||||
if event.keysym in _KEY_MAP:
|
||||
self._send(_KEY_MAP[event.keysym].encode())
|
||||
decckm = _DECCKM in self._screen.mode
|
||||
if decckm and event.keysym in _KEY_MAP_APP_CURSOR:
|
||||
self._send(_KEY_MAP_APP_CURSOR[event.keysym].encode())
|
||||
else:
|
||||
self._send(_KEY_MAP[event.keysym].encode())
|
||||
return "break"
|
||||
|
||||
# Tab
|
||||
|
||||
Reference in New Issue
Block a user