Debian Codegraph @

bin/stream_ttyrec

raw
1 #!perl
2 use strict;
3 use warnings;
4 use App::Termcast;
5 use Getopt::Long qw(:config pass_through);
6 eval { require Term::TtyRec::Plus }
7 || die "This script requires the Term::TtyRec::Plus module";
8 # PODNAME: stream_ttyrec
9 # ABSTRACT: play a ttyrec to a termcast channel
10
11
12 my ($speed, $clamp, $peek) = (1, undef, 0);
13 GetOptions(
14 'speed=f' => \$speed,
15 'clamp=f' => \$clamp,
16 'peek' => \$peek,
17 'nowait' => sub { $clamp = 0 },
18 );
19 my $tc = App::Termcast->new_with_options;
20 my @argv = @{ $tc->extra_argv };
21 @argv = (\*STDIN) unless @argv;
22
23 foreach my $file (@argv) {
24 my $ttyrec = Term::TtyRec::Plus->new(
25 (ref($file)
26 ? (filehandle => $file)
27 : (infile => $file)),
28 (defined($clamp)
29 ? (time_threshold => $clamp)
30 : ()),
31 );
32
33 if ($peek) {
34 my $fh = $ttyrec->filehandle;
35 seek $fh, 0, 2 unless $fh == \*STDIN;
36 while (1) {
37 seek $fh, 0, 1 unless $fh == \*STDIN;
38 my $frame_ref = $ttyrec->next_frame;
39 $tc->write_to_termcast($frame_ref->{data})
40 if $frame_ref;
41
42 select undef, undef, undef, 0.1;
43 }
44 }
45 else {
46 while (my $frame_ref = $ttyrec->next_frame) {
47 select undef, undef, undef, ($frame_ref->{diff} / $speed);
48 $tc->write_to_termcast($frame_ref->{data});
49 }
50 }
51 }
52
53 __END__
54
55 =pod
56
57 =encoding UTF-8
58
59 =head1 NAME
60
61 stream_ttyrec - play a ttyrec to a termcast channel
62
63 =head1 VERSION
64
65 version 0.13
66
67 =head1 SYNOPSIS
68
69 stream_ttyrec [options] [ttyrec_file]
70
71 =head1 DESCRIPTION
72
73 This program will stream a ttyrec file to the given termcast channel. The
74 ttyrec file may be given on the command line, or it will be read from STDIN.
75 See L<App::Termcast> for options documentation.
76
77 This program also accepts some additional options:
78
79 =over 4
80
81 =item C<< --speed <n> >>
82
83 Set a multiplier for how fast the ttyrec should be played back (C<--speed 2>
84 means twice as fast).
85
86 =item C<< --clamp <n> >>
87
88 Set the maximum delay between any two frames in the ttyrec. If unset, there is
89 no maximum (the ttyrec will be streamed as written).
90
91 =item C<< --nowait >>
92
93 Disable all delays between frames (equivalent to C<--clamp 0>).
94
95 =item C<< --peek >>
96
97 "Peek" at a ttyrec that is currently being written. This will seek to the end
98 of the file and stream new ttyrec frames as they become available.
99
100 =back
101
102 =head1 AUTHOR
103
104 Jesse Luehrs <[email protected]>
105
106 =head1 COPYRIGHT AND LICENSE
107
108 This software is copyright (c) 2014 by Jesse Luehrs.
109
110 This is free software; you can redistribute it and/or modify it under
111 the same terms as the Perl 5 programming language system itself.
112
113 =cut