From aeea52b238fbc2b257a4d3208b8a5d663a46113a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sat, 10 Nov 2012 00:35:01 +0100 Subject: [PATCH] wrapping use getcolour() instead of implementing it itself (code deduplication) + getcolour() recognises xterm palette changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- ponysay.py | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/ponysay.py b/ponysay.py index b28c6531..88bb0763 100755 --- a/ponysay.py +++ b/ponysay.py @@ -2173,6 +2173,22 @@ class Backend(): i += 1 di += 1 rc += c + while c == '0': + c = input[i] + i += 1 + rc += c + if c == '4': + c = input[i] + i += 1 + rc += c + if c == ';': + c = input[i] + i += 1 + rc += c + while c != '\\': + c = input[i] + i += 1 + rc += c elif c == '[': while i < n: c = input[i] @@ -2290,32 +2306,13 @@ class Backend(): if i < n: d = line[i] i += 1 - if d == '\033': # TODO this should use Backend.getcolour() + if d == '\033': ## Invisible stuff - b[bi] = d - bi += 1 - b[bi] = line[i] - d = line[i] - bi += 1 - i += 1 - if d == '[': - while True: - b[bi] = line[i] - d = line[i] - bi += 1 - i += 1 - if (('a' <= d) and (d <= 'z')) or (('A' <= d) and (d <= 'Z')) or (d == '~'): - break - elif d == ']': - b[bi] = line[i] - d = line[i] - bi += 1 - i += 1 - if d == 'P': - for j in range(0, 7): - b[bi] = line[i] - bi += 1 - i += 1 + i -= 1 + colourseq = Backend.getcolour(line, i) + b[bi : bi + len(colourseq)] = colourseq + i += len(colourseq) + bi += len(colourseq) elif (d is not None) and (d != ' '): ## Fetch word if indent == -1: