better validation, better formatting

This commit is contained in:
~d6 2020-09-04 01:09:51 -04:00
parent 062f9ea5dd
commit ab473dfb2d
1 changed files with 8 additions and 1 deletions

View File

@ -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);