tty2gif /

#!/usr/bin/env python

import os
import sys
import struct
import time
from opster import command, dispatch

header = struct.Struct('iii')

def replay(filename, factor=('f', 1, 'Speedup factor')):
    main(filename, 'replay', factor=factor)

def typing(filename):
    main(filename, 'typing')

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 =
        if not data:
        sec, usec, n = header.unpack(data)
        curtime = sec + usec/1000000.0
        if basetime is None:
            basetime = prevtime = curtime
        delay = curtime-prevtime
        prevtime = curtime
        data =
        if action == 'inspect':
            print '%8.4f %4d %s' % (delay, n, `data[:40]`)
        if action == 'replay':
        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))
                #print '-delay %d step%03d.gif' % (delay*100, stepnum),


if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.