jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1107954?usp=email )
Change subject: [FIX] Fix <<default>> color tag
......................................................................
[FIX] Fix <<default>> color tag
<<default>> color tag must be appended before the last linefeed
Also update ui_tests and usage
Bug: T382884
Change-Id: I0ec3b7c3046394af39ef25bd09517590f53a90ea
---
M pywikibot/__init__.py
M pywikibot/userinterfaces/terminal_interface_base.py
M tests/ui_tests.py
3 files changed, 15 insertions(+), 6 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 207eff1..2f6c4c0 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 @@
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():
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py
b/pywikibot/userinterfaces/terminal_interface_base.py
index e95a793..c3afee5 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 @@
# 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 @@
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 dab9f02..3a15ca5 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_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)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1107954?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0ec3b7c3046394af39ef25bd09517590f53a90ea
Gerrit-Change-Number: 1107954
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]