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 import constants as C
|
||||||
from ansible.vars import strip_internal_keys
|
from ansible.vars import strip_internal_keys
|
||||||
|
from ansible.utils.color import stringc
|
||||||
from ansible.utils.unicode import to_unicode
|
from ansible.utils.unicode import to_unicode
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -134,9 +135,17 @@ class CallbackBase:
|
||||||
fromfiledate='',
|
fromfiledate='',
|
||||||
tofiledate='',
|
tofiledate='',
|
||||||
n=10)
|
n=10)
|
||||||
difflines = list(differ)
|
has_diff = False
|
||||||
if difflines:
|
for line in differ:
|
||||||
ret.extend(difflines)
|
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')
|
ret.append('\n')
|
||||||
if 'prepared' in diff:
|
if 'prepared' in diff:
|
||||||
ret.append(to_unicode(diff['prepared']))
|
ret.append(to_unicode(diff['prepared']))
|
||||||
|
|
Loading…
Reference in a new issue