diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ekgping | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/bin/ekgping b/bin/ekgping index f01dd32..e8e7e79 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -6,7 +6,8 @@ use 5.010; use IO::Handle; use IPC::Run qw(harness io); -use File::Slurp qw(write_file); +use SDL::Mixer; +use SDL::Music; use Term::Size; use Time::HiRes qw(usleep); @@ -20,10 +21,10 @@ my $beep; my $was_beep = 1; my $dead_count = 0; my $column = 0; -my $column_max = ( Term::Size::chars * STDOUT { IO } )[0]; +my $column_max = Term::Size::chars; -my $sin = q{}; -my $in; +my $mixer = SDL::Mixer->new(); +my $beep_sound = SDL::Music->new('beep.ogg'); my $ping = harness( [ 'ping', '-n', $host ], @@ -31,10 +32,6 @@ my $ping = harness( '>&' => \&parse_ping_output, ); -my $beep_harness = harness( - io( '/dev/audio', '<', \$in ), -); - local $SIG{TERM} = \&quit; local $SIG{INT} = \&quit; @@ -43,14 +40,14 @@ sub parse_ping_output { chomp($line); - if ( $line - =~ m{ ^ \d+ \s bytes \s from \s \S+ \s + if ( + $line =~ m{ ^ \d+ \s bytes \s from \s \S+ \s icmp_req = (?<id> \d+ ) \s ttl = (?<ttl> \d+ ) \s time = (?<time> [0-9.]+) \s ms }x - ) + ) { - $id = $+{id}; + $id = $+{id}; $rtt = $+{time}; } @@ -63,18 +60,14 @@ sub quit { exit 0; } -for ( 1 .. 50 ) { - for my $i ( 0 .. 19, 18 .. 1 ) { - $sin .= chr( ( sin($i) + 1 ) * 126 ); - } -} - $ping->start(); -$beep_harness->start(); # Ignore first line $ping->pump(); +$mixer->play_music( $beep_sound, 999_999 ); +$mixer->pause_music(); + print "\e[?25l"; while ( usleep(100_000) ) { @@ -92,7 +85,7 @@ while ( usleep(100_000) ) { if ( $id != $last_id ) { $beep = 1; - if ($rtt < 300) { + if ( $rtt < 300 ) { print q{^}; } else { @@ -114,8 +107,10 @@ while ( usleep(100_000) ) { STDOUT->flush(); if ($beep) { - $in = $sin; - $beep_harness->pump_nb(); + $mixer->resume_music(); + } + else { + $mixer->pause_music(); } } |