mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
21 lines
543 B
C++
21 lines
543 B
C++
|
#include "modules/memory.hpp"
|
||
|
|
||
|
void waybar::modules::Memory::parseMeminfo() {
|
||
|
const std::string data_dir_ = "/proc/meminfo";
|
||
|
std::ifstream info(data_dir_);
|
||
|
if (!info.is_open()) {
|
||
|
throw std::runtime_error("Can't open " + data_dir_);
|
||
|
}
|
||
|
std::string line;
|
||
|
while (getline(info, line)) {
|
||
|
auto posDelim = line.find(':');
|
||
|
if (posDelim == std::string::npos) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
std::string name = line.substr(0, posDelim);
|
||
|
int64_t value = std::stol(line.substr(posDelim + 1));
|
||
|
meminfo_[name] = value;
|
||
|
}
|
||
|
}
|