From 432a1956a6386078049dd6007201f336a3b0910a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 15 Jun 2011 21:03:33 +0200 Subject: Add options (quiet, custom sound file, version) --- bin/ekgping | 71 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 19 deletions(-) (limited to 'bin/ekgping') diff --git a/bin/ekgping b/bin/ekgping index 1cd2308..8641c69 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -5,8 +5,9 @@ use warnings; use 5.010; use File::ShareDir qw(dist_file); +use Getopt::Long; use IO::Handle; -use IPC::Run qw(harness io); +use IPC::Run qw(harness); use SDL::Mixer; use SDL::Music; use Term::Size; @@ -14,18 +15,27 @@ use Time::HiRes qw(usleep); our $VERSION = '0.0'; -my $host = shift; -my $id = 0; -my $rtt = 0; -my $last_id = 0; -my $beep; -my $was_beep = 1; +my $beep = 0; +my $id = 0; +my $rtt = 0; +my $last_id = 0; my $dead_count = 0; my $column = 0; my $column_max = Term::Size::chars; +my $beep_file = dist_file( 'ekgping', 'beep.ogg' ); +my $quiet = 0; + +GetOptions( + + 'f|beep-file=s' => \$beep_file, + 'q|quiet' => \$quiet, + 'V|version' => sub { say "ekgping version ${VERSION}"; exit 0 }, + +) or usage(); + +my $host = shift or usage(); my $mixer = SDL::Mixer->new(); -my $beep_file = dist_file('ekgping', 'beep.ogg'); my $beep_sound = SDL::Music->new($beep_file); my $ping = harness( @@ -34,8 +44,9 @@ my $ping = harness( '>&' => \&parse_ping_output, ); -local $SIG{TERM} = \&quit; local $SIG{INT} = \&quit; +local $SIG{TERM} = \&quit; +local $SIG{QUIT} = \&quit; sub parse_ping_output { my ($line) = @_; @@ -46,7 +57,7 @@ sub parse_ping_output { $line =~ m{ ^ \d+ \s bytes \s from \s \S+ \s icmp_req = (? \d+ ) \s ttl = (? \d+ ) \s - time = (?