Skip to content

Commit

Permalink
Fix colorization to not extend across newline boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
ghjm committed Mar 27, 2020
1 parent 6a7e438 commit 230baeb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/ansible/utils/display.py
Expand Up @@ -153,14 +153,19 @@ def display(self, msg, color=None, stderr=False, screen_only=False, log_only=Fal
nocolor = msg

if not log_only:
if not msg.endswith(u'\n') and newline:
msg2 = msg + u'\n'

has_newline = msg.endswith(u'\n')
if has_newline:
msg2 = msg[:-1]
else:
msg2 = msg

if color:
msg2 = stringc(msg2, color)

if has_newline or newline:
msg2 = msg2 + u'\n'

msg2 = to_bytes(msg2, encoding=self._output_encoding(stderr=stderr))
if sys.version_info >= (3,):
# Convert back to text string on python3
Expand Down

0 comments on commit 230baeb

Please sign in to comment.