diff options
author | jaseg <s@jaseg.de> | 2013-04-02 02:15:02 +0200 |
---|---|---|
committer | jaseg <s@jaseg.de> | 2013-04-02 02:15:02 +0200 |
commit | 1b765e23196931c07819b5b07fc27f10c5f5a7bd (patch) | |
tree | 019a006dbc1b19cd3776e07084569c31afdd7662 | |
parent | 8e1808e4c896956efff60410279886160c9a793c (diff) | |
download | pixelterm-1b765e23196931c07819b5b07fc27f10c5f5a7bd.tar.gz pixelterm-1b765e23196931c07819b5b07fc27f10c5f5a7bd.tar.bz2 pixelterm-1b765e23196931c07819b5b07fc27f10c5f5a7bd.zip |
First optimization: Do not double-output color codes.
-rwxr-xr-x | pixelterm.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/pixelterm.py b/pixelterm.py index 5560f32..db6227e 100755 --- a/pixelterm.py +++ b/pixelterm.py @@ -8,12 +8,21 @@ def termify_pixels(img): sx, sy = img.size out = '' formatter = terminal256.Terminal256Formatter() + fg,bg = None,None def bgescape(color): + nonlocal bg + if bg == color: + return '' + bg=color r,g,b,a = color if color == (0,0,0,0): return terminal256.EscapeSequence(bg=formatter._closest_color(0,0,0)).reset_string() return terminal256.EscapeSequence(bg=formatter._closest_color(r,g,b)).color_string() def fgescape(color): + nonlocal fg + if fg == color: + return '' + fg=color r,g,b,_ = color return terminal256.EscapeSequence(fg=formatter._closest_color(r,g,b)).color_string() #NOTE: This ignores the last line if there is an odd number of lines. |