greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.88k stars 475 forks source link

pacman block - critical_updates_regex does not function #728

Closed eightballocto closed 4 years ago

eightballocto commented 4 years ago

The critical_updates_regex does not work at all, despite my numerous tests and attempts.

Example:

critical_updates_regex = "gnupg.*" should mark the block critical accordingly. grep included below for reference. image

I've tried different methods of regex, but none of them have worked to trigger the "critical" status.

ammgws commented 4 years ago

@PicoJr Whenever you have some time

PicoJr commented 4 years ago

Hello, internally we use is_match:

https://github.com/greshake/i3status-rust/blob/795e7f1235d6a5491e618e7af6a2cfa575d3f6de/src/blocks/pacman.rs#L288-L290

the regex gnupg.* looks fine, it matches gnupg 2.2.20-2 -> 2.2.20-4 cf playground

I used the following status.toml:

theme = "solarized-dark"
icons = "awesome"

[[block]]
block = "pacman"
interval = 600
format = "{count} "
format_singular = "{count} "
format_up_to_date = ""
critical_updates_regex = "gnupg.*"

my pending updates:

chromium 83.0.4103.97-1 -> 83.0.4103.97-2
gnupg 2.2.20-2 -> 2.2.20-4
gnutls 3.6.13-2 -> 3.6.14-1
iana-etc 20200511-1 -> 20200601-1
iproute2 5.6.0-1 -> 5.7.0-1
lib32-gnutls 3.6.13-2 -> 3.6.14-1
libksba 1.3.5-2 -> 1.4.0-1
librsvg 2:2.48.6-1 -> 2:2.48.7-1
linux-lts 5.4.43-1 -> 5.4.44-1
lsof 4.93.2-2 -> 4.93.2-3
man-db 2.9.1-2 -> 2.9.2-1
msgpack-c 3.2.1-1 -> 3.3.0-1
sqlite 3.32.1-1 -> 3.32.2-1

on 795e7f1, ./target/debug/i3status-rs status.toml returns:

{"version": 1, "click_events": true}
[[{"background":null,"color":"#dc322f","full_text":"","markup":"pango","separator":false,"separator_block_width":0},{"background":"#dc322f","color":"#002b36","full_text":"  13  ","markup":"pango","name":"pacman","separator":false,"separator_block_width":0}],

"#dc322f" is the solarized-dark default critical bg color, so it looks like the block state is critical.

PicoJr commented 4 years ago

@idiot-toaster

eightballocto commented 4 years ago

@idiot-toaster

* could you share your `status.toml`?

* which i3status-rust are you using?

I'm using i3status-rust-git off AUR, which was 0.13.0 when I checked.

Here is the pacman block from my status.toml.

[[block]]
block = "pacman"
interval = 600
format = "{aur}  {pacman}"
format_up_to_date = ""
# For testing purposes
critical_updates_regex = "gnupg.*"
# aur_command should output available updates to stdout (ie behave as echo -ne "update\n")
aur_command = "yay -Qua"
PicoJr commented 4 years ago

Hello,

As of 06/06/2020:

the AUR package name is i3status-rust-git 0.13.0.r940.ga42de8b-2

this package name is built using:

  echo $(grep '^version =' Cargo.toml|head -n1|cut -d\" -f2).r$(git rev-list --count HEAD).g$(git describe --always)

the corresponding commit is a42de8b-2

@idiot-toaster could you confirm the package name of the i3status-rust-git AUR? do you use the latest one available? it would help pinpoint the exact git revision you are using :)

eightballocto commented 4 years ago

Upon checking with yay it seems that I do have an earlier revision of the package; i3status-rust-git 0.13.0.r1183.g795e7f1-1 But it does confuse me why yay did not inform me about updates. Perhaps this might be an issue with yay itself.

This does answer some questions though, thank you!

EDIT: Trying to retrieve with yay gives me the same package version, so it seems I'm still stuck yet.

ammgws commented 4 years ago

I moved to pikaur from yay a long while ago and haven't looked back.

Can you try the block without the AUR stuff and see if the regex works?

ammgws commented 4 years ago

@DrBluefall Do you experience this as well?

ammgws commented 4 years ago

@idiot-toaster Is this still occurring?

eightballocto commented 4 years ago

@ammgws Yes, it is. After further testing, I've discovered that this issue occurs when you specify both the AUR and Pacman string substitutes in the same block. If you take away {aur} then it works. e.g. format = "{aur} {pacman}" will not be highlighted but format = "{pacman}" will

PicoJr commented 4 years ago
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/blocks/pacman.rs
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 322   │             Watched::Both(aur_command) => {
 323   │                 check_fakeroot_command_exists()?;
 324   │                 let pacman_available_updates = get_pacman_available_updates()?;
 325   │                 let aur_available_updates = get_aur_available_updates(&aur_command)?;
 326   │                 let pacman_count = get_update_count(&pacman_available_updates);
 327   │                 let aur_count = get_update_count(&aur_available_updates);
 328   │                 let formatting_map = map!("{count}" => pacman_count, "{pacman}" => pacman_count, "{aur}" => aur_count, "{both}" => pacman_coun
       │ t + aur_count);
 329   │                 let critical = self.critical_updates_regex.as_ref().map_or(false, |regex| {
 330   │                     has_critical_update(&aur_available_updates, regex)
 331   │                         || has_critical_update(&aur_available_updates, regex)
 332   │                 });
 333   │                 (formatting_map, critical, pacman_count + aur_count)
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Line 331 should be has_critical_update(&pacman_available_updates, regex), only AUR critical updates are checked when both (AUR and pacman) are watched.

Well spotted.