From 09a0fc29b38be6f04e005928b1f2dc9c0a32d41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=91=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=D1=80=D0=B5=D0=B2?= Date: Thu, 21 May 2026 00:06:57 +0300 Subject: [PATCH] fix: _write closure bug + strip \r instead of line-delete Co-Authored-By: Claude Opus 4.6 --- ssh_manager.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/ssh_manager.py b/ssh_manager.py index 07a14b4..4e7b27b 100644 --- a/ssh_manager.py +++ b/ssh_manager.py @@ -816,35 +816,27 @@ class TerminalWidget(tk.Frame): self.after(100, self.on_close) def _write(self, text, tag=None): + # Strip \r before closure (SSH sends \r\n) + clean = text.replace("\r", "") if not tag else text + def _do(): self.text.configure(state=tk.NORMAL) if tag: - self.text.insert(tk.END, text, tag) - elif "\x08" not in text and "\x7f" not in text and "\r" not in text: - # Fast path: no control chars - self.text.insert(tk.END, text) + self.text.insert(tk.END, clean, tag) + elif "\x08" not in clean and "\x7f" not in clean: + # Fast path: no backspace chars + self.text.insert(tk.END, clean) else: - # Slow path: handle backspace/DEL/CR char by char + # Handle backspace/DEL char by char buf = [] - for ch in text: + for ch in clean: if ch == "\x08" or ch == "\x7f": - # Flush buffer first if buf: self.text.insert(tk.END, "".join(buf)) buf.clear() - # Delete char before cursor pos = self.text.index(tk.END + "-2c") if self.text.compare(pos, ">", "1.0"): self.text.delete(pos) - elif ch == "\r": - if buf: - self.text.insert(tk.END, "".join(buf)) - buf.clear() - # CR: delete current line content for overwrite - line_start = self.text.index(tk.END + "-1c linestart") - line_end = self.text.index(tk.END + "-1c") - if self.text.compare(line_start, "<", line_end): - self.text.delete(line_start, line_end) else: buf.append(ch) if buf: