fix logclean for6wind
This commit is contained in:
+27
-7
@@ -23,14 +23,34 @@ def log_cleaner(data: str) -> str:
|
|||||||
elif token in ('\b', '\x7f'):
|
elif token in ('\b', '\x7f'):
|
||||||
if cursor > 0:
|
if cursor > 0:
|
||||||
cursor -= 1
|
cursor -= 1
|
||||||
elif token == '\x1B[D': # Left Arrow
|
elif token.startswith('\x1B[') and len(token) >= 3:
|
||||||
if cursor > 0:
|
# Parse CSI: \x1B[ <params> <final_char>
|
||||||
cursor -= 1
|
final = token[-1]
|
||||||
elif token == '\x1B[C': # Right Arrow
|
param_str = token[2:-1]
|
||||||
if cursor < len(buffer):
|
n = int(param_str) if param_str.isdigit() else 1
|
||||||
cursor += 1
|
|
||||||
elif token == '\x1B[K': # Clear to end of line
|
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]
|
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'):
|
elif token.startswith('\x1B'):
|
||||||
continue
|
continue
|
||||||
elif len(token) == 1 and ord(token) < 32:
|
elif len(token) == 1 and ord(token) < 32:
|
||||||
|
|||||||
Reference in New Issue
Block a user