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

Add option to adjust power consumption format replacement field precision #2963

Closed
ajgae opened this issue Feb 24, 2024 · 6 comments
Closed

Comments

@ajgae
Copy link

ajgae commented Feb 24, 2024

current behavior

the {power} (power in watts) format replacement can take up a variable amount of characters, which sometimes leads to a shorter or longer character count for the battery module on my waybar:

image
image

better behavior

allow the user to specify the amount of decimal places so that character count stays constant (essentially something like %4.2f in printf)

@jramrath
Copy link
Contributor

I think making an option to configure the number of decimals is not necessary.

I'll make a PR to always shows two decimals.

@alebastr
Copy link
Contributor

essentially something like %4.2f in printf

That should translate to {power:4.2f}. Does it do what you wanted?

@phonetic112
Copy link

You could use padright() from the string library in Lua, but that might have some limitations if your generated text is larger than your field width so choose wisely.

@ajgae
Copy link
Author

ajgae commented Feb 26, 2024

That should translate to {power:4.2f}. Does it do what you wanted?

@alebastr sadly it does not, this seems to have no effect at all.

I think making an option to configure the number of decimals is not necessary.

I'll make a PR to always shows two decimals.

@jramrath i think it might be good to have the option, as some people may be short on waybar space and want to only show one or even no decimals. But I think showing only two by default may still be an improvement. Do you know where in the codebase the format string interpolation is done, and whether it would be reasonably easy to implement an option for number of decimals? (something like {power:4.2f} like suggested above, or via an additional key-value pair in the json config file)?

@ajgae
Copy link
Author

ajgae commented Feb 26, 2024

I see now that waybar uses the {fmt} library for label formatting. Given the official example for how fmt::arg works, and the way it is used in the battery module, it seems the {power:4.2f} suggestion should work. Why does it not?

@ajgae
Copy link
Author

ajgae commented Feb 26, 2024

Nevermind this. I was simply changing the value of the format key in my config file while having unchanged format-discharging and format-charging values. The {power:4.2f} suggestion does work. I now also realize that this is mentioned in the FAQ, so my bad for opening the issue. I think it may be useful to mention that {fmt} is used as the formatting library in the configuration section of the wiki, but it's up to the people who maintain the documentation to see if it they think it fit to be mentioned there as well.

@ajgae ajgae closed this as completed Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants