mirror of https://github.com/aristocratos/btop.git
ugly hack to get battery
This commit is contained in:
parent
d5e6725c6c
commit
ce51031142
|
@ -324,8 +324,29 @@ namespace Cpu {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_battery() -> tuple<int, long, string> {
|
auto get_battery() -> tuple<int, long, string> {
|
||||||
// if (not has_battery)
|
if (not has_battery) return {0, 0, ""};
|
||||||
return {0, 0, ""};
|
|
||||||
|
int percent = -1;
|
||||||
|
long seconds = -1;
|
||||||
|
string status = "discharging";
|
||||||
|
|
||||||
|
FILE *bat = popen("pmset -g batt", "r");
|
||||||
|
if (bat) {
|
||||||
|
char buf[2048];
|
||||||
|
if (fgets(buf, sizeof(buf), bat) != NULL) {
|
||||||
|
char *perc = strstr(buf, "%");
|
||||||
|
if (perc) {
|
||||||
|
has_battery = true;
|
||||||
|
perc -= 3;
|
||||||
|
string p(perc);
|
||||||
|
p.resize(3);
|
||||||
|
percent = atoi(p.c_str());
|
||||||
|
} else {
|
||||||
|
has_battery = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {percent, seconds, status};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto collect(const bool no_update) -> cpu_info & {
|
auto collect(const bool no_update) -> cpu_info & {
|
||||||
|
|
Loading…
Reference in New Issue