App-sdif
view release on metacpan or search on metacpan
lib/App/watchdiff.pm view on Meta::CPAN
has help => ' h ' ;
has version => ' ' ;
has debug => ' d ' ;
has unit => ' by :s ' ;
has diff => ' =s ' ;
has exec => ' e =s@ ' , default => [] ;
has refresh => ' r :1 ' , default => 1 ;
has interval => ' i =i ' , default => 2 ;
has count => ' c =i ' , default => 1000 ;
has clear => ' ! ' , default => 1 ;
has silent => ' s ! ' , default => 0 ;
has mark => ' M ! ' , default => 0 ;
has verbose => ' V ! ' , default => undef ;
has old => ' O ! ' , default => 0 ;
has date => ' D ! ' , default => 1 ;
has newline => ' N ! ' , default => 1 ;
has context => ' C :2 ' , default => 999, alias => 'U';
has scroll => ' S ' , default => 1 ;
has colormap => ' cm =s@ ' , default => [] ;
has plain => ' p ' ,
action => sub {
$_->date = $_->newline = 0;
};
has '+help' => action => sub {
pod2usage
-verbose => 99,
-sections => [ qw(SYNOPSIS VERSION) ];
};
has '+version' => action => sub {
print "$version\n";
exit;
};
} no Getopt::EX::Hashed;
my %colormap = qw(
APPEND K/544
DELETE K/544
OCHANGE K/445
NCHANGE K/445
OTEXT K/455E
NTEXT K/554E
);
use Term::ANSIColor::Concise qw(ansi_code csi_code);
my %termcap = pairmap { $a => ansi_code($b) }
qw(
home {CUP}
clear {CUP}{ED2}
el {EL}
ed {ED}
decsc {DECSC}
decrc {DECRC}
);
sub run {
$app = my $opt = shift;
local @ARGV = @_;
use Getopt::EX::Long;
Getopt::Long::Configure(qw(bundling require_order));
$opt->getopt or usage({status => 1});
if ($opt->context and $opt->context < 100) {
$opt->verbose //= 1;
}
use Getopt::EX::Colormap;
my $cm = Getopt::EX::Colormap
->new(HASH => \%colormap)
->load_params(@{$opt->colormap});
if (@ARGV) {
push @{$opt->exec}, [ @ARGV ];
} else {
@{$opt->exec} or pod2usage();
}
setup_terminal();
$SIG{INT} = sub { exit };
$opt->do_loop();
}
END {
reset_terminal();
}
sub control_scroll {
my $opt = shift;
$opt->scroll && $opt->date && $opt->refresh == 1;
}
sub setup_terminal {
if ($app and $app->control_scroll) {
STDOUT->printflush(csi_code(STBM => 3, 999));
}
}
sub reset_terminal {
if ($app and $app->control_scroll) {
STDOUT->printflush($termcap{decsc},
csi_code(STBM =>),
$termcap{decrc});
}
}
sub do_loop {
my $opt = shift;
use Command::Run;
my $old = Command::Run->new(@{$opt->exec->[0]});
my $new = Command::Run->new(@{$opt->exec->[0]});
my @default_diff = (
qw(cdif --no-unknown),
map { ('--cm', "$_=$colormap{$_}") } sort keys %colormap
);
( run in 0.596 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )