i3status-rust
i3status-rust copied to clipboard
block custom format
[[block]]
block = "custom"
command = "get_bandwith"
interval = 1
// ...
unsigned long diff_packet = update_tx_packets(tx_packets) / 1024;
char s[5];
snprintf(s, sizeof(s), "%4lu", diff_packet);
printf("%4s kb\n", s);
I am currently padding my numbers with blank spaces when they are less than 4 characters long. However, the output appears to be trimmed by i3status-rs. I would prefer to avoid having the blocks in my status bar move around when the status is updated.
https://github.com/greshake/i3status-rust/blob/master/src/blocks/custom.rs#L242
True, we do trim the normal output. As a workaround, you can use JSON mode though:
[[block]]
block = "custom"
json = true
command = "get_bandwith"
interval = 1
// ...
printf("{\"text\":\"%4s kb\"}\n", s);
Since this trimming was like this for a long time i don't know if it makes sense to change it now since it's basically expected behavior, but @MaxVerevkin might have some better insight. Maybe it's only done to get rid of newlines?
think's for your help.
I think the better way to handle trimming is to make a custom block support some format like:
UPDATE
[[block]]
block = "custom"
command = "get_bandwith"
format = "{custom:4}"
that's easy to understand and more expected
That's also not a bad idea imo, maybe awk-style with $1,$2/$@ for the individual words/whole line of the output?
Maybe it's only done to get rid of newlines?
Probably. And it's been there since at least v0.10 :)
Also how about extending the json protocol like this?
{
"vals": [
"bandwith": 1234
]
}
[[block]]
block = "custom"
command = "get_bandwith"
format = " $bandwith.eng(w:4) "
That looks neat but doesn't really solve the issue at hand since @ayoubelmhamdi is looking for a solution without using JSON i think? Both would be nice though
I find it relatively straightforward to manipulate the output utilizing the format field exclusively, while handling JSON is not particularly difficult.
I had the same issue and I already use JSON.
I was going to say that the spaces are still trimmed, but I looked more closely and it's just that the spaces width is smaller than other characters. Even if I use a pure Mono font patched with Nerd-fonts in mono.
I would just like to leave here that you should use U+2002, a '1 en' width space for padding, like seen here.
It works nice with the json custom block.
Edit: U+2007 would be even better it should be the width of a digit.