File: ttyplay

package info (click to toggle)
libterm-ttyrec-plus-perl 0.09-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 596 kB
  • sloc: perl: 2,219; makefile: 7
file content (105 lines) | stat: -rw-r--r-- 2,184 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env perl
use strict;
use warnings;

use Term::TtyRec::Plus;

use Getopt::Long;

sub usage {
    my ($exit) = @_;

    my $out = $exit ? \*STDERR : \*STDOUT;

    print { $out }
          "$0 [-s <speed>] [-c <delay_clamp>] [-n] [-p] <ttyrec_files>\n";

    exit($exit);
}

my ($speed, $clamp, $peek) = (1, undef, 0);
GetOptions(
    'speed=f' => \$speed,
    'clamp=f' => \$clamp,
    'peek'    => \$peek,
    'nowait'  => sub { $clamp = 0 },
    'help'    => sub { usage(0) },
) || usage(1);

$|++;

foreach my $file (@ARGV) {
    my $ttyrec = Term::TtyRec::Plus->new(
        infile => $file,
        (defined($clamp)
            ? (time_threshold => $clamp)
            : ()),
    );

    if ($peek) {
        my $fh = $ttyrec->filehandle;
        seek $fh, 0, 2;
        while (1) {
            seek $fh, 0, 1;
            my $frame_ref = $ttyrec->next_frame;
            print $frame_ref->{data}
                if $frame_ref;

            select undef, undef, undef, 0.1;
        }
    }
    else {
        while (my $frame_ref = $ttyrec->next_frame) {
            select undef, undef, undef, ($frame_ref->{diff} / $speed);
            print $frame_ref->{data};
        }
    }
}

__END__

=head1 NAME

ttyplay - play back ttyrec files

=head1 SYNOPSIS

  ttyplay [-s <speed>] [-c <delay_clamp>] [-n] [-p] <ttyrec_files>

=head1 OPTIONS

=over 4

=item C<--speed> (C<-s>)

Set a multiplier for how fast the ttyrec should be played back (C<-s 2> means
twice as fast).

=item C<--clamp> (C<-c>)

Set the maximum delay between any two frames in the ttyrec. If unset, there is
no maximum (the ttyrec will be played as written).

=item C<--nowait> (C<-n>)

Disable all delays between frames (equivalent to C<-c 0>).

=item C<--peek> (C<-p>)

"Peek" at a ttyrec that is currently being written. This will seek to the end
of the file and display new ttyrec frames as they become available.

=back

=head1 AUTHOR

Jesse Luehrs <doy at tozt dot net>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jesse Luehrs.

This is free software; you can redistribute it and/or modify it under the same
terms as the Perl 5 programming language system itself.

=cut