From e4fd1adba3ee384d39bd7cf48a39e0a66b3b12a0 Mon Sep 17 00:00:00 2001 From: Fede Luzzi Date: Fri, 15 May 2026 17:32:09 -0300 Subject: [PATCH] fix logclean for6wind --- connpy/utils.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/connpy/utils.py b/connpy/utils.py index d82d92b..33a7a0d 100644 --- a/connpy/utils.py +++ b/connpy/utils.py @@ -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 - buffer = buffer[:cursor] + elif token.startswith('\x1B[') and len(token) >= 3: + # Parse CSI: \x1B[ + 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: