Skip to content
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

Merged
merged 3 commits into from Mar 28, 2020

Conversation

ghjm
Copy link
Contributor

@ghjm ghjm commented Mar 27, 2020

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
  • Bugfix Pull Request
COMPONENT NAME

utils

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Mar 27, 2020
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 27, 2020
@ryanpetrello
Copy link
Contributor

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:

image

@ryanpetrello
Copy link
Contributor

ryanpetrello commented Mar 27, 2020

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'))
Copy link
Contributor Author

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)

@ghjm
Copy link
Contributor Author

ghjm commented Mar 27, 2020

It would be nice to have some version of this also backported to 2.9.x.

FWIW, this cherry-picks without problems to the stable-2.9 branch.

@mattclay mattclay removed the needs_triage Needs a first human triage before being processed. label Mar 27, 2020
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 27, 2020
@mattclay mattclay merged commit 2068131 into ansible:devel Mar 28, 2020
ghjm added a commit to ghjm/ansible that referenced this pull request Mar 28, 2020
* 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)
mattclay pushed a commit that referenced this pull request Apr 15, 2020
* 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)
@ansible ansible locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants