diff options
-rw-r--r-- | bin/ttyrec | 10 | ||||
-rw-r--r-- | lib/App/Ttyrec.pm | 65 |
2 files changed, 75 insertions, 0 deletions
diff --git a/bin/ttyrec b/bin/ttyrec new file mode 100644 index 0000000..aa9b966 --- /dev/null +++ b/bin/ttyrec @@ -0,0 +1,10 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use App::Ttyrec; + +@ARGV = ($ENV{SHELL} || '/bin/sh') + unless @ARGV; + +App::Ttyrec->new->run(@ARGV); diff --git a/lib/App/Ttyrec.pm b/lib/App/Ttyrec.pm index e69de29..e1ac0ae 100644 --- a/lib/App/Ttyrec.pm +++ b/lib/App/Ttyrec.pm @@ -0,0 +1,65 @@ +package App::Ttyrec; +use Moose; + +use Scalar::Util 'weaken'; +use Term::Filter; +use Tie::Handle::TtyRec; + +has ttyrec_file => ( + is => 'ro', + isa => 'Str', + default => 'ttyrecord', +); + +has append => ( + is => 'ro', + isa => 'Bool', + default => 0, +); + +has ttyrec => ( + is => 'ro', + isa => 'FileHandle', + lazy => 1, + default => sub { Tie::Handle::TtyRec->new(shift->ttyrec_file) }, +); + +has term => ( + is => 'ro', + isa => 'Term::Filter', + lazy => 1, + default => sub { + my $self = shift; + weaken(my $weakself = $self); + Term::Filter->new( + callbacks => { + munge_output => sub { + my ($event, $got) = @_; + + print { $weakself->ttyrec } $got; + + $got; + }, + }, + ); + }, +); + +sub BUILD { + my $self = shift; + + die "Appending is not currently supported" + if $self->append; +} + +sub run { + my $self = shift; + my (@cmd) = @_; + + $self->term->run(@cmd); +} + +__PACKAGE__->meta->make_immutable; +no Moose; + +1; |