mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add simple --diff colour support
This commit is contained in:
parent
6ddea3e915
commit
8edcca0ef5
1 changed files with 12 additions and 3 deletions
|
@ -28,6 +28,7 @@ from ansible.compat.six import string_types
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible.vars import strip_internal_keys
|
||||
from ansible.utils.color import stringc
|
||||
from ansible.utils.unicode import to_unicode
|
||||
|
||||
try:
|
||||
|
@ -134,9 +135,17 @@ class CallbackBase:
|
|||
fromfiledate='',
|
||||
tofiledate='',
|
||||
n=10)
|
||||
difflines = list(differ)
|
||||
if difflines:
|
||||
ret.extend(difflines)
|
||||
has_diff = False
|
||||
for line in differ:
|
||||
has_diff = True
|
||||
if line.startswith('-'):
|
||||
line = stringc(line, 'red')
|
||||
elif line.startswith('+'):
|
||||
line = stringc(line, 'green')
|
||||
elif line.startswith('@@'):
|
||||
line = stringc(line, 'cyan')
|
||||
ret.append(line)
|
||||
if has_diff:
|
||||
ret.append('\n')
|
||||
if 'prepared' in diff:
|
||||
ret.append(to_unicode(diff['prepared']))
|
||||
|
|
Loading…
Reference in a new issue