greshake / i3status-rust

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

feature: add `format_alt` and `format_list` to all blocks #2014

Open martinpelikan opened 4 months ago

martinpelikan commented 4 months ago

I looked briefly, so I might have missed it, but I can't find a way to add a format_alt to the external_ip block via the config. I suppose that means it needs to be added explicitly via the block code. That being said, I wonder if it would be more versatile to have add a format_alt in the core block code, and have a click handler to switch to it for all blocks, rather than only those that have it explicitly defined.

I understand other blocks such as notify have different behavior on left click, but I hope it should be possible to override the behavior in their code, and also modify it with the click config without any conflict.

Additionally, it might also be nice to be able to use the scroll wheel to iterate through all the initialized (or configured) values available to the format code, and similarly override the scroll wheel behavior used in blocks like volume. So, for example, scrolling on external_ip would cycle through a format_list value containing: ["ip", "version", "city", "region", "region_code", "..."] by default. The user could configure format_list to trim it down to only those relevant to them, eg:

[[block]]
block = "external_ip"
format = "$ip"
format_list = ["$ip", "$city", "$asn"]

P.S. Thank you for everyone's ongoing effort to improve the project. Every few months when I revisit my config and the release notes, there's always an improvement I appreciate.

bim9262 commented 4 months ago

I don't think that we'd want to make every block have an alt format or list of formats. For example take a look at the pomodoro block which has several states in which clicking/scrolling have different actions.

martinpelikan commented 4 months ago

@bim9262 Thank you for the quick response.

Shall I change the request to only modify external_ip then? I suggested the change as a default because most blocks appear to follow the same pattern, while the interactive ones are more of an exception. Looking closer, there probably isn't much benefit, and might actually complicate existing code rather than simplify it.

bim9262 commented 4 months ago

I'm sure some of the other non-interactive would benefit from having an alt format option. Instead of a format list option though mayt it would be better to allow a single or list of alt formats so that we don't need to set both.

See the Untagged section: https://serde.rs/enum-representations.html

The clock block may be interesting to you check out to see how we added the ability to display different timezones. While it's not actually a different format it's similar in concept.