mirror of
https://github.com/andrey271192/ssh-manage.git
synced 2026-09-20 11:55:37 +00:00
fix: _write closure bug + strip \r instead of line-delete
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -816,35 +816,27 @@ class TerminalWidget(tk.Frame):
|
|||||||
self.after(100, self.on_close)
|
self.after(100, self.on_close)
|
||||||
|
|
||||||
def _write(self, text, tag=None):
|
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():
|
def _do():
|
||||||
self.text.configure(state=tk.NORMAL)
|
self.text.configure(state=tk.NORMAL)
|
||||||
if tag:
|
if tag:
|
||||||
self.text.insert(tk.END, text, tag)
|
self.text.insert(tk.END, clean, tag)
|
||||||
elif "\x08" not in text and "\x7f" not in text and "\r" not in text:
|
elif "\x08" not in clean and "\x7f" not in clean:
|
||||||
# Fast path: no control chars
|
# Fast path: no backspace chars
|
||||||
self.text.insert(tk.END, text)
|
self.text.insert(tk.END, clean)
|
||||||
else:
|
else:
|
||||||
# Slow path: handle backspace/DEL/CR char by char
|
# Handle backspace/DEL char by char
|
||||||
buf = []
|
buf = []
|
||||||
for ch in text:
|
for ch in clean:
|
||||||
if ch == "\x08" or ch == "\x7f":
|
if ch == "\x08" or ch == "\x7f":
|
||||||
# Flush buffer first
|
|
||||||
if buf:
|
if buf:
|
||||||
self.text.insert(tk.END, "".join(buf))
|
self.text.insert(tk.END, "".join(buf))
|
||||||
buf.clear()
|
buf.clear()
|
||||||
# Delete char before cursor
|
|
||||||
pos = self.text.index(tk.END + "-2c")
|
pos = self.text.index(tk.END + "-2c")
|
||||||
if self.text.compare(pos, ">", "1.0"):
|
if self.text.compare(pos, ">", "1.0"):
|
||||||
self.text.delete(pos)
|
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:
|
else:
|
||||||
buf.append(ch)
|
buf.append(ch)
|
||||||
if buf:
|
if buf:
|
||||||
|
|||||||
Reference in New Issue
Block a user