Reduced flickering

This commit is contained in:
jaseg 2014-01-13 21:52:22 +01:00
parent af5f0f28b1
commit 755b369ff9
2 changed files with 7 additions and 5 deletions

View file

@ -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:

View file

@ -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():