from subprocess import Popen, PIPE


def colordiff(diff):
    """Colorize diff output using external program colordiff"""
    try:
        p = Popen(["colordiff"], stdin=PIPE, stdout=PIPE, close_fds=True)
        outs, _errs = p.communicate(diff.encode('utf8'))
        return outs.decode('utf8')
    except OSError:
        return diff

