mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(config): format modules
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
#include "modules/cpu.hpp"
|
||||
#include <iostream>
|
||||
|
||||
waybar::modules::Cpu::Cpu()
|
||||
waybar::modules::Cpu::Cpu(Json::Value config)
|
||||
: _config(config)
|
||||
{
|
||||
_label.get_style_context()->add_class("cpu");
|
||||
_thread = [this] {
|
||||
@ -15,8 +16,9 @@ auto waybar::modules::Cpu::update() -> void
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
||||
_label.set_text(fmt::format("{:.{}f}% ",
|
||||
info.loads[0] * f_load * 100 / get_nprocs(), 0));
|
||||
int load = info.loads[0] * f_load * 100 / get_nprocs();
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
||||
_label.set_text(fmt::format(format, load));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user