-
Notifications
You must be signed in to change notification settings - Fork 478
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
Implement new formatting mechanism #1112
Conversation
c95c391
to
7bf78dd
Compare
I don't understand the use case for var~icon. Any examples? |
Net block displays speed as |
7bf78dd
to
b0f181a
Compare
Also, an error will be shown if any icon was not found. I think it's better than |
6bbdb1e
to
8aca111
Compare
Maybe instead of having |
Sounds OK to me. |
8ce54ac
to
9ec0323
Compare
Would something like this be OK: |
So it would pad the string? I don't get why the minimum is 0 in that example. Is this what you mean (replaced spaces with □ to make it easier to tell):
|
Oh sorry I thought you were talking about strings because of your comment on the other PR. Didn't realise you were talking about the barchart.
I assume your min and max are referring to the ones used by our current function? |
This feature would remove redundant placeholders like i3status-rust/src/blocks/disk_space.rs Lines 274 to 275 in 094cfdc
and give ability to draw bar for, lets say, sound block, as well as every other block. |
Oh wow I totally forgot that even existed. It's not even documented for the sound block. Anyway, right now I can't think of any cases where configuring the min would be useful, so perhaps it may be OK to hardcode it at 0. One nit: the proposed syntax kinda looks like a number range due to the "~", so perhaps another char would be better. And maybe explicitly declare that it's a barchart to make it more obvious as well. "{var:bar:5:110}" or something. |
Sound block doesn't have this feature.
The parsing I currently have doesn't work well (at all) with repeated "keys" ( |
9ec0323
to
82ef88e
Compare
src/blocks/sound.rs
40:use crate::util::{format_percent_bar, FormatTemplate};
856: format_percent_bar(volume as f32)
870: format_percent_bar(volume as f32)
Sure why not. We can overview the overall syntax for everything once it gets nearer to completion, and get some more feedback from other interested parties too. |
Ohhh, well, that's weird 😆 |
Memory block also has a bunch of undocumented format key specifiers that output a percentage bar 😆 src/blocks/memory.rs
277: "{MFpb}" => format_percent_bar(mem_free.percent(mem_total)),
282: "{MUpb}" => format_percent_bar(mem_total_used.percent(mem_total)),
287: "{Mupb}" => format_percent_bar(mem_used.percent(mem_total)),
292: "{MApb}" => format_percent_bar(mem_avail.percent(mem_total)),
299: "{SFpb}" => format_percent_bar(swap_free.percent(swap_total)),
304: "{SUpb}" => format_percent_bar(swap_used.percent(swap_total)),
309: "{Bpb}" => format_percent_bar(buffers.percent(mem_total)),
314: "{Cpb}" => format_percent_bar(cached.percent(mem_total))); |
An exception |
Ah yes the classic millipercent, also known as the centipermille :D |
No, bits are default only for |
I meant in general use, not this software. But it doesn't really matter as long as both are possible |
It may be, since before it would have been displayed as "1.92Kb" and now it's "1.92Kb/s", and I imagine there are people who want to keep it short by removing the "/s" part. (Actually I am one of those people but I don't have it set to bits 😃 ) |
Bits for network speed, but when actually downloading files to disk (browser, torrents, etc), if my memory is correct then it's almost always been bytes. |
Honestly same, but i don't really know how we could completely decouple the actual unit from the displayed unit unless we made the entire unit after the prefix customizable, which would then make it hard to semantically get the desired units (b vs B) from it (but it would probably be possible) |
A little TODO:
|
Is there a way to do what @ammgws wanted? A way do discard the
i.e. matching the used unit by finding the substring Or is that too difficult? |
|
Oof 😆 |
How about adding bits as a unit and then just allowing conversion between BitsPerSecond/BytesPerSecond and Bits/Bytes? |
It still would not give enough flexibility to, for example, switch between If just hiding the unit with |
Since we only have bits/bytes per second and not per minute/hour/etc then just remove them and have Bits and Bytes only. The "/s" part can be added in the format string. Especially since there are other ways people might want to write it, such as "Kbps" instead "Kb/s" |
c9122a4
to
cd637be
Compare
cd637be
to
f31fba7
Compare
OK, at least it would look the same way it was before. |
877131a
to
a070fdf
Compare
By the way, would it be possible to use |
If it makes things easier, I don't see why not. Something to look at in the future. |
OK I've done as much testing as I can. Excellent work on this! |
Yeah honestly great work :) Thanks! |
An attempt to close #1108. Any thoughts on this PR are welcome.
Overview
The syntax for the formatting string placeholders is (the order doesn't matter, but the name must always be first)
Examples of configs:
format = "{signal_strength:2} {graph_down}{speed_down;K}{speed_up;1*Bi/s}"
format = "{volume:03}"
format = "{volume:5#110} {volume:03}"
- demoExamples of code (blocks' POV):
Temperature:
Speed test:
Sound:
TODO
render_static_str()
Allow users to override placeholders' icon withwill not implement.{var~icon}
max_width
for strings. Something like"{var.5}"
will truncate the text to first 5 characters.Extend(not useful becauseValue
to have colors (via pango)i3
renderspango
differently compared tosway
)