Commit 65ea172c authored by Peter Pentchev's avatar Peter Pentchev

p6: reduce the scope of some more variables.

parent 20e806cb
......@@ -10,8 +10,6 @@ use strict;
use Getopt::Tiny;
use Terminal::ANSIColor;
my Bool $use_color;
sub version()
{
say 'ethstats 1.1.1';
......@@ -118,7 +116,6 @@ class InterfaceStats {
}
my InterfaceStats %prevstat;
my InterfaceStats $total;
grammar Interfaces {
token TOP {
......@@ -177,7 +174,7 @@ class InterfaceActions {
method uint($/) { $/.make: $/.UInt }
}
sub convert(Str $iface, UInt:D $period)
sub convert(Str $iface, UInt:D $period, InterfaceStats:D $total)
{
try my $f = open :r, '/proc/net/dev', :chomp(False), :enc('latin1');
die "Could not open the interface info pseudo-file: $!" if $!;
......@@ -208,11 +205,6 @@ sub convert(Str $iface, UInt:D $period)
return %devs;
}
sub acolor(Str:D $name)
{
return $use_color?? color($name)!! '';
}
{
my Bool %flags;
my Getopt::Tiny $opts .= new;
......@@ -244,7 +236,7 @@ sub acolor(Str:D $name)
my Str $iface = Nil;
$opts.str('i', Nil, -> $v { $iface = $v; });
$use_color = $*OUT.t;
my Bool $use_color = $*OUT.t;
$opts.bool('C', Nil, -> $v {
if %flags<M> {
note 'The -C and -M options are mutually exclusive';
......@@ -274,16 +266,15 @@ sub acolor(Str:D $name)
exit 0;
}
$total .= new(:name('total'));
convert $iface, 1;
my Str %c = <yellow reset>.map: { $_ => $use_color?? color($_)!! '' };
my InterfaceStats $total .= new(:name('total'));
convert $iface, 1, $total;
sleep 1;
loop {
my InterfaceStats %devs = convert $iface, $period;
my InterfaceStats %devs = convert $iface, $period, $total;
print time ~ ' ' if $addtime;
if %devs.elems > 1 {
say acolor('yellow') ~
$total.format ~
acolor('reset');
say %c<yellow> ~ $total.format ~ %c<reset>;
}
.format.say for %devs.values.sort: *.name;
if $count > 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment