From 1395cafa45ff826145b8f3495d1277f352ff0e57 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 22 Sep 2024 13:26:59 +0100 Subject: more fun with symbols --- battery | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/battery b/battery index 589c228..a6de32b 100755 --- a/battery +++ b/battery @@ -56,30 +56,36 @@ sub update { my $deriv = $bs->{power_now} // $bs->{current_now}; my $e=$now/$full; - my $txt=''; my $charging = lc($bs->{status}) eq 'charging'; my $is_full = lc($bs->{status}) eq 'full'; - if ($charging) { - $txt = "\x{1f50c}"; - } - elsif (!$is_full) { - $txt = "\x{1f50b}"; - } + my @symbols; + my $time_estimate=''; + my $percentage=sprintf '%.0f%%', 100*$e; + my $fraction=$e; + if ($deriv && !$charging) { my $t=$now/$deriv; my $tot=$full/$deriv; - $txt .= sprintf "%s/%s\x{2009}", + $time_estimate = sprintf "%s/%s", _format_time($t), - _format_time($tot); - $bar->set_fraction($t/$tot); + _format_time($tot); + $fraction= $t/$tot; } - else { - $bar->set_fraction($e); + + if ($charging) { + push @symbols, "\x{1f50c}"; + } + + if (!$is_full && $fraction > 0.5) { + push @symbols, "\x{1f50b}"; + } + elsif (!$is_full) { + push @symbols, "\x{1faab}"; } - $txt .= sprintf '%.0f%%', 100*$e; - $bar->set_text($txt); + $bar->set_fraction($fraction); + $bar->set_text(join "\x{2009}", grep { length } @symbols, $time_estimate, $percentage); return 1; } -- cgit v1.2.3