aboutsummaryrefslogtreecommitdiff
path: root/pixelterm
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-01-13 21:52:22 +0100
committerjaseg <jaseg@jaseg.net>2014-01-13 21:52:22 +0100
commit755b369ff9a564af3bee5273ebc929e76dacf81d (patch)
treec371fa666f8b731a765d16efb6386a7f1690049e /pixelterm
parentaf5f0f28b155de04e331b880617c68d1c01748e6 (diff)
downloadpixelterm-755b369ff9a564af3bee5273ebc929e76dacf81d.tar.gz
pixelterm-755b369ff9a564af3bee5273ebc929e76dacf81d.tar.bz2
pixelterm-755b369ff9a564af3bee5273ebc929e76dacf81d.zip
Reduced flickering
Diffstat (limited to 'pixelterm')
-rwxr-xr-xpixelterm/gifterm.py8
-rwxr-xr-xpixelterm/pixelterm.py4
2 files changed, 7 insertions, 5 deletions
diff --git a/pixelterm/gifterm.py b/pixelterm/gifterm.py
index 03cbabd..7ca25ed 100755
--- a/pixelterm/gifterm.py
+++ b/pixelterm/gifterm.py
@@ -5,6 +5,7 @@ import pixelterm
from PIL import Image, GifImagePlugin, ImageSequence
clear_screen = '\033[H\033[2J'
+home_cursor = '\033[H'
cursor_invisible = '\033[?25l'
cursor_visible = '\033[?25h'
@@ -44,7 +45,7 @@ def main():
im = last_frame.copy()
if (tw, th) != (None, None):
im.thumbnail((tw, th), Image.NEAREST)
- frames.append(pixelterm.termify_pixels(im))
+ frames.append(pixelterm.termify_pixels(im, True))
if args.serve:
from socketserver import ThreadingMixIn, TCPServer, BaseRequestHandler
@@ -60,7 +61,7 @@ def main():
self.request.sendall(bytes(cursor_invisible, "UTF-8"))
while True:
for frame in frames:
- self.request.sendall(bytes(clear_screen + pixelterm.reset_sequence, "UTF-8"))
+ self.request.sendall(bytes(home_cursor + pixelterm.reset_sequence, "UTF-8"))
self.request.sendall(bytes(frame, "UTF-8"))
time.sleep(min(1/10, img.info['duration']/1000.0))
except:
@@ -76,7 +77,8 @@ def main():
try:
while True:
for frame in frames:
- print(clear_screen, pixelterm.reset_sequence)
+ print(home_cursor)
+ print(pixelterm.reset_sequence)
print(frame)
time.sleep(min(1/10, img.info['duration']/1000.0))
except KeyboardInterrupt:
diff --git a/pixelterm/pixelterm.py b/pixelterm/pixelterm.py
index 30af163..74fe9f1 100755
--- a/pixelterm/pixelterm.py
+++ b/pixelterm/pixelterm.py
@@ -4,7 +4,7 @@ import xtermcolors
reset_sequence = '\033[39;49m'
-def termify_pixels(img):
+def termify_pixels(img, fill=False):
sx, sy = img.size
out = ''
@@ -66,7 +66,7 @@ def termify_pixels(img):
if colbot == coltop:
c,te,be = cf,te,te
out += te(coltop) + be(colbot) + c
- out = (out.rstrip() if bg == (0,0,0,0) else out) + '\n'
+ out = (out.rstrip() if bg == (0,0,0,0) and not fill else out) + '\n'
return out[:-1] + reset_sequence + '\n'
def main():