diff --git a/main.py b/main.py index a82d28b..77411d2 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ import tqdm import spotipy -from utils.progress_line import parse_progress_line +from utils.progress_line import is_blank_console_line, parse_progress_line # --- CORRECCIÓN DE CODIFICACIÓN PARA EMOJIS EN WINDOWS --- if sys.stdout is not None and hasattr(sys.stdout, 'reconfigure'): @@ -331,6 +331,9 @@ def _append(): self.progress_bar.set(percent / 100) return + if is_blank_console_line(text): + return + self.log_textbox.configure(state="normal") self.log_textbox.insert("end", text) self.log_textbox.configure(state="disabled") diff --git a/tests/test_progress_line.py b/tests/test_progress_line.py index 5105fca..771982d 100644 --- a/tests/test_progress_line.py +++ b/tests/test_progress_line.py @@ -6,7 +6,7 @@ if project_root not in sys.path: sys.path.append(project_root) -from utils.progress_line import parse_progress_line +from utils.progress_line import is_blank_console_line, parse_progress_line def test_plain_progress_line_is_recognised(): @@ -42,13 +42,27 @@ def test_non_numeric_progress_is_not_recognised(): def test_empty_input_is_not_recognised(): assert parse_progress_line("") is None - assert parse_progress_line(None) is None # type: ignore[arg-type] + assert parse_progress_line(None) is None def test_plain_log_line_is_passed_through(): assert parse_progress_line("Doing stuff\n") is None +def test_blank_console_line_is_suppressed(): + assert is_blank_console_line("") + assert is_blank_console_line("\n") + assert is_blank_console_line("\r") + assert is_blank_console_line("\r\n") + assert is_blank_console_line(" \r\n") + assert is_blank_console_line(None) + + +def test_non_blank_console_line_is_not_suppressed(): + assert not is_blank_console_line("Processing tracks\n") + assert not is_blank_console_line(" PROG:50\n") + + if __name__ == "__main__": # Allow running directly: `python tests/test_progress_line.py`. test_plain_progress_line_is_recognised() @@ -60,4 +74,6 @@ def test_plain_log_line_is_passed_through(): test_non_numeric_progress_is_not_recognised() test_empty_input_is_not_recognised() test_plain_log_line_is_passed_through() + test_blank_console_line_is_suppressed() + test_non_blank_console_line_is_not_suppressed() print("[OK] all parse_progress_line tests passed") diff --git a/utils/progress_line.py b/utils/progress_line.py index ef6a3a9..6200732 100644 --- a/utils/progress_line.py +++ b/utils/progress_line.py @@ -24,7 +24,7 @@ _PROG_LINE_RE = re.compile(r"^\s*PROG:(\d+)\s*$") -def parse_progress_line(text: str) -> Optional[int]: +def parse_progress_line(text: Optional[str]) -> Optional[int]: """Return the integer percentage if ``text`` is a progress directive. Returns ``None`` for any line that is not a standalone ``PROG:`` @@ -40,3 +40,14 @@ def parse_progress_line(text: str) -> Optional[int]: return int(match.group(1)) except (TypeError, ValueError): return None + + +def is_blank_console_line(text: Optional[str]) -> bool: + """Return ``True`` for output chunks that should not reach the log. + + Progress-producing tools such as ``tqdm`` often emit standalone + carriage returns or empty newline chunks while redrawing a progress + line. Those chunks create visual blank rows in the GUI console, so the + log textbox should ignore them entirely. + """ + return text is None or text.strip() == ""