#!/usr/bin/python
import fileinput

from plumbum.cli import Application, SwitchAttr
from random import normalvariate
from sys import stdout
from time import sleep

class SlowCat(Application):
    r'''Concatenate files or input, pausing after each line.
    '''#"""#'''
    
    VERSION = "0.1"
    
    delay = SwitchAttr(
        ["-d", "--delay"],
        default = 0.2,
        argtype = float,
        #argname = "SECONDS",
        help = "Average delay, in seconds",
    )
    
    sigma = SwitchAttr(
        ["-s", "--sigma"],
        default = 0,
        argtype = float,
        #argname = "SECONDS",
        help = "Standard deviation, in seconds",
    )
    
    def main(self, *files):
        for line in fileinput.input(files):
            try:
                stdout.write(line)
                delay = normalvariate(self.delay, self.sigma)
                if delay > 0:
                    sleep(delay)
            except (KeyboardInterrupt, IOError):
                return 1
        return 0

if __name__ == "__main__":
    SlowCat.run()
