Created
May 5, 2016 10:12
-
-
Save tuxfight3r/4b078e44d89f9e5785eb3d4e34fdbd73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import struct | |
import time | |
from opster import command, dispatch | |
header = struct.Struct('iii') | |
@command() | |
def replay(filename, factor=('f', 1, 'Speedup factor')): | |
main(filename, 'replay', factor=factor) | |
@command() | |
def typing(filename): | |
main(filename, 'typing') | |
@command() | |
def inspect(filename): | |
main(filename, 'inspect') | |
def main(filename, action, factor=1): | |
winid = int(os.getenv('WINDOWID')) | |
script = open(filename) | |
basetime = None | |
prevtime = None | |
stepnum = 0 | |
args = [] | |
while True: | |
data = script.read(header.size) | |
if not data: | |
break | |
sec, usec, n = header.unpack(data) | |
curtime = sec + usec/1000000.0 | |
if basetime is None: | |
basetime = prevtime = curtime | |
delay = curtime-prevtime | |
prevtime = curtime | |
data = script.read(n) | |
if action == 'inspect': | |
print '%8.4f %4d %s' % (delay, n, `data[:40]`) | |
continue | |
if action == 'replay': | |
time.sleep(delay/factor) | |
elif action == 'typing': | |
delay = 0 | |
if n == 1: | |
delay = 0.2 | |
elif data.startswith('\r\n'): | |
delay = 0.5 | |
if delay: | |
os.system('import -window %s step%03d.gif' % (winid, stepnum)) | |
#time.sleep(delay) | |
#print '-delay %d step%03d.gif' % (delay*100, stepnum), | |
stepnum+=1 | |
sys.stdout.write(data) | |
sys.stdout.flush() | |
if __name__ == '__main__': | |
dispatch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It might be worth mentioning that this script will only run on a terminal opened in an X GUI, (i.e. GNOME/KDE etc).
You can get as far as recording your terminal with
ttyrec
, but that is it!