summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-02-25 14:58:09 -0600
committerJesse Luehrs <doy@tozt.net>2012-02-25 14:58:09 -0600
commita334f1e8441d26b8322c35a6148694540d1d908e (patch)
tree3198762d91f70281f9adeb380220d5d7fef44030
parentdd812b9a3340173b72f82d257cfa92ef6e077fd5 (diff)
downloadapp-termcast-a334f1e8441d26b8322c35a6148694540d1d908e.tar.gz
app-termcast-a334f1e8441d26b8322c35a6148694540d1d908e.zip
add some more features to stream_ttyrec
-rw-r--r--bin/stream_ttyrec74
1 files changed, 62 insertions, 12 deletions
diff --git a/bin/stream_ttyrec b/bin/stream_ttyrec
index 6998974..67f2d9a 100644
--- a/bin/stream_ttyrec
+++ b/bin/stream_ttyrec
@@ -2,6 +2,7 @@
use strict;
use warnings;
use App::Termcast;
+use Getopt::Long qw(:config pass_through);
eval { require Term::TtyRec::Plus }
|| die "This script requires the Term::TtyRec::Plus module";
# PODNAME: stream_ttyrec
@@ -17,21 +18,70 @@ This program will stream a ttyrec file to the given termcast channel. The
ttyrec file may be given on the command line, or it will be read from STDIN.
See L<App::Termcast> for options documentation.
+This program also accepts some additional options:
+
+=over 4
+
+=item C<< --speed <n> >>
+
+Set a multiplier for how fast the ttyrec should be played back (C<--speed 2>
+means twice as fast).
+
+=item C<< --clamp <n> >>
+
+Set the maximum delay between any two frames in the ttyrec. If unset, there is
+no maximum (the ttyrec will be streamed as written).
+
+=item C<< --nowait >>
+
+Disable all delays between frames (equivalent to C<--clamp 0>).
+
+=item C<< --peek >>
+
+"Peek" at a ttyrec that is currently being written. This will seek to the end
+of the file and stream new ttyrec frames as they become available.
+
+=back
+
=cut
+my ($speed, $clamp, $peek) = (1, undef, 0);
+GetOptions(
+ 'speed=f' => \$speed,
+ 'clamp=f' => \$clamp,
+ 'peek' => \$peek,
+ 'nowait' => sub { $clamp = 0 },
+);
my $tc = App::Termcast->new_with_options;
-my ($file) = @{ $tc->extra_argv };
+my @argv = @{ $tc->extra_argv };
+@argv = (\*STDIN) unless @argv;
-my $fh;
-if (defined($file)) {
- open $fh, '<', $file or die "Couldn't open ttyrec $file for reading: $!";
-}
-else {
- $fh = \*STDIN;
-}
+foreach my $file (@argv) {
+ my $ttyrec = Term::TtyRec::Plus->new(
+ (ref($file)
+ ? (filehandle => $file)
+ : (infile => $file)),
+ (defined($clamp)
+ ? (time_threshold => $clamp)
+ : ()),
+ );
+
+ if ($peek) {
+ my $fh = $ttyrec->filehandle;
+ seek $fh, 0, 2 unless $fh == \*STDIN;
+ while (1) {
+ seek $fh, 0, 1 unless $fh == \*STDIN;
+ my $frame_ref = $ttyrec->next_frame;
+ $tc->write_to_termcast($frame_ref->{data})
+ if $frame_ref;
-my $ttyrec = Term::TtyRec::Plus->new(filehandle => $fh);
-while (my $frame = $ttyrec->next_frame) {
- select undef, undef, undef, $frame->{diff};
- $tc->write_to_termcast($frame->{data});
+ select undef, undef, undef, 0.1;
+ }
+ }
+ else {
+ while (my $frame_ref = $ttyrec->next_frame) {
+ select undef, undef, undef, ($frame_ref->{diff} / $speed);
+ $tc->write_to_termcast($frame_ref->{data});
+ }
+ }
}