diff --git a/i3status-anyevent b/i3status-anyevent index b4aab9a..66e7d67 100644 --- a/i3status-anyevent +++ b/i3status-anyevent @@ -374,8 +374,7 @@ sub add_events () { while ($str = pop (@up)) { if (substr ($str, 4, 10) eq 'percentage') { - $percentage = substr $str, 25; - chomp $percentage; + $percentage = substr $str, 25, -1; # chop % symbol ath the end of the string } elsif (substr ($str, 4, 5) eq 'state') { if (substr ($str, 25, 11) eq 'discharging') { $state = '▼'; @@ -395,6 +394,18 @@ sub add_events () { return; } + my $color = ''; + + if ($percentage > 85) { + $color = ''; + } elsif ($percentage < 25 && $percentage > 15) { + $color = ''; + } elsif ($percentage <= 15 && $percentage > 11) { + $color = ''; + } elsif ($percentage <= 11) { + $color = ''; + } + if (defined $time_to) { chomp $time_to; @@ -413,7 +424,7 @@ sub add_events () { $time_to = '00:00'; } - my $charge = sprintf '⚡ %s %s %s', $percentage, $state, $time_to; + my $charge = sprintf '⚡ %s%s%% %s %s', $color, $percentage, $state, $time_to; if (! defined $O->{battery}->{'full_text'}) { $O->{battery}->{'full_text'} = $charge; @@ -491,19 +502,19 @@ sub add_events () { } my $capacity = int (100 * ($current_charge / $charge_max)); - my $color = ''; + my $color = ''; if ($capacity > 85) { - $color = ''; + $color = ''; } elsif ($capacity < 25 && $capacity > 15) { - $color = ''; + $color = ''; } elsif ($capacity <= 15 && $capacity > 11) { - $color = ''; + $color = ''; } elsif ($capacity <= 11) { - $color = ''; + $color = ''; } - my $charge = sprintf '⚡ %s%s%% %s', $color, $capacity, $state; + my $charge = sprintf '⚡ %s%s%% %s', $color, $capacity, $state; if ($O->{battery}->{'full_text'} ne $charge) { $O->{battery}->{'full_text'} = $charge; @@ -617,15 +628,15 @@ sub add_events () { if (defined $mtime) { if ((time () - $mtime) < $CONF->{vpn}->{mtime_threshold}) { - $vpnstr .= '⍋'; + $vpnstr .= sprintf '⍋', $CONF->{vpn}->{up_color}; } else { - $vpnstr .= '⍒'; + $vpnstr .= sprintf '⍒', $CONF->{vpn}->{down_color}; } $file_check_mtime = $mtime; } else { $mtime = 0; - $vpnstr .= '⍒'; + $vpnstr .= sprintf '⍒', $CONF->{vpn}->{up_down}; } # Try to tcp connect to server in vpn network @@ -644,13 +655,14 @@ sub add_events () { ) { $sock->shutdown (SHUT_WR); $sock->close (); - $vpnstr .= '✔'; + $vpnstr .= sprintf '✔', $CONF->{vpn}->{up_color}; } else { - $vpnstr .= '✘'; + $vpnstr .= sprintf '✘', $CONF->{vpn}->{down_color}; } } if (! defined $O->{vpn}->{'full_text'}) { + $O->{vpn}->{'markup'} = 'pango'; $O->{vpn}->{'full_text'} = $vpnstr; $O->{vpn}->{'color'} = '#3e78fd'; $UPDATE = 1; diff --git a/i3status-anyevent.json b/i3status-anyevent.json index 67d8071..a990348 100644 --- a/i3status-anyevent.json +++ b/i3status-anyevent.json @@ -53,6 +53,9 @@ # state file and update its timestamp at least as frequent as mtime_threshold in seconds "vpn": { "enabled": 0, +# html (actually, pango) notation + "down_color" : "red", + "up_color" : "green", "statusfile" : "/tmp/openvpn-status.stat", "mtime_threshold": 10, # Also we can tcp-ping some service inside vpn network to ensure that connection is not stoned