From 8edcca0ef5a0dea6df6c65a9d8c407965c7a4f74 Mon Sep 17 00:00:00 2001 From: George Christou Date: Mon, 15 Feb 2016 22:18:59 +0000 Subject: [PATCH] Add simple --diff colour support --- lib/ansible/plugins/callback/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 1fa6c03753..ce028dc279 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -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']))