Skip to content

Commit

Permalink
Merge "[FIX] Fix <<default>> color tag"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 9, 2025
2 parents 6513471 + ab350be commit f342be6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pywikibot/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -338,7 +338,7 @@ def remaining() -> tuple[int, datetime.timedelta]:
num, sec = remaining()
if num > 0 and sec.total_seconds() > _config.noisysleep:
output(f'<<lightblue>>Waiting for {num} pages to be put. '
f'Estimated time remaining: {sec}<<default>>')
f'Estimated time remaining: {sec}')

exit_queue = None
if _putthread is not threading.current_thread():
Expand Down
13 changes: 11 additions & 2 deletions pywikibot/userinterfaces/terminal_interface_base.py
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/ui_tests.py
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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 <<red>>world you!\n',
self.ui_obj.stdout)
Expand Down

0 comments on commit f342be6

Please sign in to comment.