diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 207eff1e23..2f6c4c081e 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -1,6 +1,6 @@ """The initialization file for the Pywikibot framework.""" # -# (C) Pywikibot team, 2008-2024 +# (C) Pywikibot team, 2008-2025 # # Distributed under the terms of the MIT license. # @@ -338,7 +338,7 @@ def remaining() -> tuple[int, datetime.timedelta]: num, sec = remaining() if num > 0 and sec.total_seconds() > _config.noisysleep: output(f'<>Waiting for {num} pages to be put. ' - f'Estimated time remaining: {sec}<>') + f'Estimated time remaining: {sec}') exit_queue = None if _putthread is not threading.current_thread(): diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index e95a793a4c..c3afee5346 100644 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -1,6 +1,6 @@ """Base for terminal user interfaces.""" # -# (C) Pywikibot team, 2003-2024 +# (C) Pywikibot team, 2003-2025 # # Distributed under the terms of the MIT license. # @@ -194,7 +194,15 @@ def _print(self, text, target_stream) -> None: # Therefore we need this stack. color_stack = ['default'] text_parts = colorTagR.split(text) - text_parts.append('default') + + # Add default before the last linefeed + if text.endswith('\n'): + text_parts[-1] = re.sub(r'\r?\n\Z', '', text_parts[-1]) + text_parts.extend(('default', None, None, + '\n', 'default', None, None)) + else: + text_parts.append('default') + # match.split() includes every regex group; for each matched color # fg_col:b_col, fg_col and bg_col are added to the resulting list. len_text_parts = len(text_parts[::4]) @@ -210,6 +218,7 @@ def _print(self, text, target_stream) -> None: if current_color != next_color: colored_line = True + if colored_line and not colorized: if '\n' in txt: # Normal end of line txt = txt.replace('\n', ' ***\n', 1) diff --git a/tests/ui_tests.py b/tests/ui_tests.py index dab9f0236c..3a15ca565b 100755 --- a/tests/ui_tests.py +++ b/tests/ui_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Tests for the user interface.""" # -# (C) Pywikibot team, 2008-2022 +# (C) Pywikibot team, 2008-2025 # # Distributed under the terms of the MIT license. # @@ -449,7 +449,7 @@ def test_stack_implicit_color(self): def test_one_color_newline(self): """Test with trailing new line and one color.""" - self._colors = (('red', 6), ('default', 11)) + self._colors = (('red', 6), ('default', 10)) with redirect_stdout(self.redirect) as f: self.ui_obj._print('Hello <>world you!\n', self.ui_obj.stdout)