From 4ff5c2e992aea195a80c2d9c83449e9dc5d88094 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 22 Aug 2012 23:16:03 +0200 Subject: [PATCH] Add color to console output and fix some things from review. --- tools/debug-proxy.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/debug-proxy.py b/tools/debug-proxy.py index cf84bd54..3ff6f561 100755 --- a/tools/debug-proxy.py +++ b/tools/debug-proxy.py @@ -4,9 +4,12 @@ import argparse import difflib import sys -from gevent import select -from gevent import server -from gevent import socket +from gevent import select, server, socket + +COLORS = ['\033[1;%dm' % (30+i) for i in range(8)] +BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = COLORS +RESET = "\033[0m" +BOLD = "\033[1m" def proxy(client, address, reference_address, actual_address): @@ -53,7 +56,7 @@ def loop(client, address, reference, actual): disconnected = read([reference, actual], responses, find_response_end_token) diff(address, '', responses[reference], responses[actual]) - # We lost the a backend, might as well give up. + # We lost a backend, might as well give up. if disconnected: return @@ -138,7 +141,17 @@ def diff(address, command, reference_response, actual_response): actual_response.splitlines(True), fromfile='Reference response', tofile='Actual response'): + + if line.startswith('+') and not line.startswith('+++'): + sys.stdout.write(GREEN) + elif line.startswith('-') and not line.startswith('---'): + sys.stdout.write(RED) + elif line.startswith('@@'): + sys.stdout.write(CYAN) + sys.stdout.write(line) + sys.stdout.write(RESET) + sys.stdout.flush()