better validation, better formatting
This commit is contained in:
parent
062f9ea5dd
commit
ab473dfb2d
|
@ -49,17 +49,24 @@ sub perc {
|
||||||
|
|
||||||
sub charge_time {
|
sub charge_time {
|
||||||
my ($data) = @_;
|
my ($data) = @_;
|
||||||
return $data->{full} ? "--:--" : stime($data->{tcharge});
|
return "--:--" if $data->{full} || $data->{tcharge} == 0;
|
||||||
|
return stime($data->{tcharge});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub drain_time {
|
sub drain_time {
|
||||||
my ($data) = @_;
|
my ($data) = @_;
|
||||||
|
return "--:--" if $data->{tdrain} == 0;
|
||||||
return stime($data->{tdrain});
|
return stime($data->{tdrain});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub main {
|
sub main {
|
||||||
if (@ARGV) {
|
if (@ARGV) {
|
||||||
my $t = $ARGV[0];
|
my $t = $ARGV[0];
|
||||||
|
# require a positive number of seconds (e.g. 2, 4.5, 0.2, ...)
|
||||||
|
unless ($t =~ m/^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)$/) {
|
||||||
|
print "usage: $0 [POLL-SECS]\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
run();
|
run();
|
||||||
select(undef, undef, undef, $t);
|
select(undef, undef, undef, $t);
|
||||||
|
|
Loading…
Reference in New Issue