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:
@@ -8,6 +8,8 @@ import customtkinter as ctk
|
||||
from core.ssh_client import ShellSession
|
||||
from core.i18n import t
|
||||
|
||||
import queue
|
||||
|
||||
|
||||
class TerminalTab(ctk.CTkFrame):
|
||||
def __init__(self, master, store):
|
||||
@@ -30,8 +32,8 @@ class TerminalTab(ctk.CTkFrame):
|
||||
self._terminal.pack(fill="both", expand=True, padx=5, pady=5)
|
||||
self._terminal.set_status(t("term_disconnected"), "#888888")
|
||||
|
||||
# Data batching buffer
|
||||
self._data_buffer = bytearray()
|
||||
# Thread-safe data batching
|
||||
self._data_queue: queue.Queue[bytes] = queue.Queue()
|
||||
self._flush_after_id = None
|
||||
|
||||
def set_server(self, alias: str | None):
|
||||
@@ -88,16 +90,20 @@ class TerminalTab(ctk.CTkFrame):
|
||||
self._session = None
|
||||
|
||||
def _on_data_received(self, data: bytes):
|
||||
self._data_buffer.extend(data)
|
||||
if self._flush_after_id is None:
|
||||
self._flush_after_id = self.after(8, self._flush_data_buffer)
|
||||
"""Called from SSH thread — put data in thread-safe queue."""
|
||||
self._data_queue.put(data)
|
||||
self.after(0, self._flush_data_queue)
|
||||
|
||||
def _flush_data_buffer(self):
|
||||
self._flush_after_id = None
|
||||
if self._data_buffer:
|
||||
chunk = bytes(self._data_buffer)
|
||||
self._data_buffer.clear()
|
||||
self._terminal.feed(chunk)
|
||||
def _flush_data_queue(self):
|
||||
"""Called on main thread — drain queue and feed terminal."""
|
||||
chunks = []
|
||||
try:
|
||||
while True:
|
||||
chunks.append(self._data_queue.get_nowait())
|
||||
except queue.Empty:
|
||||
pass
|
||||
if chunks:
|
||||
self._terminal.feed(b"".join(chunks))
|
||||
|
||||
def _on_disconnected(self):
|
||||
if self._intentional_disconnect:
|
||||
|
||||
Reference in New Issue
Block a user