feat(Cpu): dynamic fmt args
This commit is contained in:
parent
4dd36890c1
commit
2d9bcb1a2d
|
@ -13,13 +13,20 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void {
|
||||
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||
auto cpu_load = getCpuLoad();
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(tooltip);
|
||||
std::vector<fmt::basic_format_arg<fmt::format_context>> args;
|
||||
if (format_.find("{load}") != std::string::npos) {
|
||||
auto cpu_load = getCpuLoad();
|
||||
args.emplace_back(fmt::internal::make_arg<fmt::format_context>(fmt::arg("load", cpu_load)));
|
||||
}
|
||||
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||
if (format_.find("{usage}") != std::string::npos) {
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
args.emplace_back(fmt::internal::make_arg<fmt::format_context>(fmt::arg("usage", cpu_usage)));
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(tooltip);
|
||||
}
|
||||
}
|
||||
label_.set_markup(
|
||||
fmt::vformat(format_, fmt::basic_format_args<fmt::format_context>(args.data(), args.size())));
|
||||
}
|
||||
|
||||
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
||||
|
|
Loading…
Reference in New Issue