fix logclean for6wind

This commit is contained in:
2026-05-15 17:32:09 -03:00
parent b0a914ad7f
commit e4fd1adba3
+27 -7
View File
@@ -23,14 +23,34 @@ def log_cleaner(data: str) -> str:
elif token in ('\b', '\x7f'):
if cursor > 0:
cursor -= 1
elif token == '\x1B[D': # Left Arrow
if cursor > 0:
cursor -= 1
elif token == '\x1B[C': # Right Arrow
if cursor < len(buffer):
cursor += 1
elif token == '\x1B[K': # Clear to end of line
elif token.startswith('\x1B[') and len(token) >= 3:
# Parse CSI: \x1B[ <params> <final_char>
final = token[-1]
param_str = token[2:-1]
n = int(param_str) if param_str.isdigit() else 1
if final == 'D': # CUB Cursor Back
cursor = max(0, cursor - n)
elif final == 'C': # CUF Cursor Forward
cursor = min(len(buffer), cursor + n)
elif final == 'K': # EL Erase in Line
if n == 0 or param_str == '': # Clear to end
buffer = buffer[:cursor]
elif n == 1: # Clear to start
buffer[:cursor] = [' '] * cursor
elif n == 2: # Clear entire line
buffer = []
cursor = 0
elif final == 'G': # CHA Cursor Horizontal Absolute (1-indexed)
cursor = max(0, n - 1)
# Pad buffer if cursor is beyond current length
if cursor > len(buffer):
buffer.extend([' '] * (cursor - len(buffer)))
elif final == 'P': # DCH Delete Characters
del buffer[cursor:cursor + n]
elif final == '@': # ICH Insert Characters
buffer[cursor:cursor] = [' '] * n
# All other CSI sequences are silently discarded
elif token.startswith('\x1B'):
continue
elif len(token) == 1 and ord(token) < 32: