better validation, better formatting
This commit is contained in:
parent
062f9ea5dd
commit
ab473dfb2d
|
@ -49,17 +49,24 @@ sub perc {
|
|||
|
||||
sub charge_time {
|
||||
my ($data) = @_;
|
||||
return $data->{full} ? "--:--" : stime($data->{tcharge});
|
||||
return "--:--" if $data->{full} || $data->{tcharge} == 0;
|
||||
return stime($data->{tcharge});
|
||||
}
|
||||
|
||||
sub drain_time {
|
||||
my ($data) = @_;
|
||||
return "--:--" if $data->{tdrain} == 0;
|
||||
return stime($data->{tdrain});
|
||||
}
|
||||
|
||||
sub main {
|
||||
if (@ARGV) {
|
||||
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 {
|
||||
run();
|
||||
select(undef, undef, undef, $t);
|
||||
|
|
Loading…
Reference in New Issue