New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix colorization to not extend across newline boundary #68517
Conversation
this PR replaces #68375 and is intended to address the issue reported in AWX: ansible/awx#6357 I can report that it resolves the issue for me: |
It would be nice to have some version of this also backported to 2.9.x. |
@@ -27,7 +27,7 @@ def test_warning(capsys, mocker, warning_message): | |||
d.warning(warning_message) | |||
out, err = capsys.readouterr() | |||
assert d._warns == {expected_warning_message: 1} | |||
assert err == '\x1b[1;35m{0}\x1b[0m\n\x1b[1;35m\x1b[0m'.format(expected_warning_message.rstrip('\n')) | |||
assert err == '\x1b[1;35m{0}\x1b[0m\n'.format(expected_warning_message.rstrip('\n')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was originally looking for:
\x1b[1;35m
(color on) - {0}
(the message) - \x1b[0m
(color off) - \n
(newline) - \x1b[1;35m
(color on) - \x1b[0m
(color off)
With this PR it now puts the newline outside the coloration, and does not unnecessarily turn the coloration on and off a second time. So it is now looking for:
\x1b[1;35m
(color on) - {0}
(the message) - \x1b[0m
(color off) - \n
(newline)
FWIW, this cherry-picks without problems to the stable-2.9 branch. |
* Fix colorization to not extend across newline boundary * Fix unit test to look for the newline outside the coloration * Add changelog fragment (cherry picked from commit 2068131)
* Fix colorization to not extend across newline boundary * Fix unit test to look for the newline outside the coloration * Add changelog fragment (cherry picked from commit 2068131)
SUMMARY
The change in #65199 causes Tower formatting of stdout to break. The problem is that the ANSI color codes are added in a way that includes the newline within the colorization. If we colorize the string and then add the newline outside the color codes, everyone should be happy.
ISSUE TYPE
COMPONENT NAME
utils