Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #89 support running a block only once #684

Merged
merged 12 commits into from
May 17, 2020
Merged

Conversation

PicoJr
Copy link
Contributor

@PicoJr PicoJr commented May 14, 2020

Fix #89

interval = 2  # every 2 seconds
interval = "once" # only update once
# interval not provided, use default value

This PR modifies the Block trait and adds an Update enum:

    /// Forces an update of the internal state of the block.
-    fn update(&mut self) -> Result<Option<Duration>> {
+    fn update(&mut self) -> Result<Option<Update>> {
pub enum Update {
    Every(Duration), // update every <duration> seconds
    Once, // only update once
}

What do you think?

How to try this PR

status.toml:

[[block]]
block = "custom"
command = "date"
interval = 2 # updated every 2 seconds

[[block]]
block = "custom"
command = "date"
interval = "once" # only updated once

[[block]]
block = "custom"
command = "date"
# no interval provided, updated every 10 seconds

./target/debug/i3status-rs test.toml

Then check the first block is updated every 2 seconds, the 2nd block only once and 3rd block every 10 seconds.

TODO before merge

  • rebase
  • rename Refresh to Update ?
  • add doc
  • does it make sense to support running once for other blocks?

@PicoJr PicoJr changed the title Fix #89 (WIP) support running a block only once Fix #89 support running a block only once May 15, 2020
@PicoJr PicoJr force-pushed the feat-once branch 2 times, most recently from 247148b to b135948 Compare May 16, 2020 10:04
src/blocks.rs Outdated Show resolved Hide resolved
blocks.md Outdated Show resolved Hide resolved
@ammgws
Copy link
Collaborator

ammgws commented May 17, 2020

does it make sense to support running once for other blocks?

TLDR: "maybe"

Block Has update interval? Run once sensible?
Backlight no -
Battery yes no
Bluetooth no -
CPU Utilization yes no
Custom yes yes
Custom DBus no -
Disk Space yes maybe
Focused Window no -
IBus no -
Keyboard Layout yes maybe
Load yes no
Maildir yes no
Memory yes no
Music no -
Net yes no
NetworkManager no -
Notmuch yes no
Nvidia Gpu yes maybe
Pacman yes no
Pomodoro yes no
Sound no -
Speed Test yes maybe
Taskwarrior yes no
Temperature yes no
Time yes no
Toggle yes yes
Uptime yes no
Watson yes no
Weather yes maybe
Xrandr yes maybe

@ammgws
Copy link
Collaborator

ammgws commented May 17, 2020

I was mulling whether we should go with a mixed keyword/numeric option like you've proposed here or just purely numeric based with -1 representing "run once". However I just checked i3blocks and they use mixed so I guess it's OK. If we ever introduce any other interval modes, having a named option would be better than trying to remember what -2 means.

i3blocks interval options:

  • <non-zero number>
  • -1 or once
  • -2 or repeat
  • -3 or persist

@PicoJr
Copy link
Contributor Author

PicoJr commented May 17, 2020

Thanks for your feedback: I'll rebase and resolve conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make custom block command run once
2 participants