1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #14491 from gechr/gc-simple-colour-diff

Add simple --diff colour support
This commit is contained in:
Brian Coca 2016-02-18 02:00:03 -08:00
commit 5300a2eafc
2 changed files with 15 additions and 3 deletions

View file

@ -278,6 +278,9 @@ COLOR_SKIP = get_config(p, 'colors', 'skip', 'ANSIBLE_COLOR_SKIP', 'cyan'
COLOR_UNREACHABLE = get_config(p, 'colors', 'unreachable', 'ANSIBLE_COLOR_UNREACHABLE', 'bright red') COLOR_UNREACHABLE = get_config(p, 'colors', 'unreachable', 'ANSIBLE_COLOR_UNREACHABLE', 'bright red')
COLOR_OK = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_OK', 'green') COLOR_OK = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_OK', 'green')
COLOR_CHANGED = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_CHANGED', 'yellow') COLOR_CHANGED = get_config(p, 'colors', 'ok', 'ANSIBLE_COLOR_CHANGED', 'yellow')
COLOR_DIFF_ADD = get_config(p, 'colors', 'diff_add', 'ANSIBLE_COLOR_DIFF_ADD', 'green')
COLOR_DIFF_REMOVE = get_config(p, 'colors', 'diff_remove', 'ANSIBLE_COLOR_DIFF_REMOVE', 'red')
COLOR_DIFF_LINES = get_config(p, 'colors', 'diff_lines', 'ANSIBLE_COLOR_DIFF_LINES', 'cyan')
# non-configurable things # non-configurable things
MODULE_REQUIRE_ARGS = ['command', 'shell', 'raw', 'script'] MODULE_REQUIRE_ARGS = ['command', 'shell', 'raw', 'script']

View file

@ -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, C.COLOR_DIFF_ADD)
elif line.startswith('-'):
line = stringc(line, C.COLOR_DIFF_REMOVE)
elif line.startswith('@@'):
line = stringc(line, C.COLOR_DIFF_LINES)
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']))