This code is probably terrible but its ok
This commit is contained in:
parent
8db3dae6f1
commit
e8fb8ec19f
10 changed files with 201 additions and 219 deletions
|
@ -1,11 +1,7 @@
|
|||
module;
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <playerctl/playerctl.h>
|
||||
#include <fstream>
|
||||
|
||||
export module OS;
|
||||
|
||||
using std::string;
|
||||
|
||||
uint64_t parse_line_as_number(const string& input) {
|
||||
|
@ -13,15 +9,13 @@ uint64_t parse_line_as_number(const string& input) {
|
|||
string::size_type start = 0;
|
||||
|
||||
// Skip leading non-numbers
|
||||
while (!isdigit(input[++start]))
|
||||
;
|
||||
while (!isdigit(input[++start]));
|
||||
|
||||
// Start searching from the start of the number
|
||||
string::size_type end = start;
|
||||
|
||||
// Increment to the end of the number
|
||||
while (isdigit(input[++end]))
|
||||
;
|
||||
while (isdigit(input[++end]));
|
||||
|
||||
// Return the substring containing the number
|
||||
return std::stoul(input.substr(start, end - start));
|
||||
|
@ -31,16 +25,15 @@ uint64_t meminfo_parse(std::ifstream is) {
|
|||
string line;
|
||||
|
||||
// Skip every line before the one that starts with "MemTotal"
|
||||
while (std::getline(is, line) && !line.starts_with("MemTotal"))
|
||||
;
|
||||
while (std::getline(is, line) && !line.starts_with("MemTotal"));
|
||||
|
||||
// Parse the number from the line
|
||||
const auto num = parse_line_as_number(line);
|
||||
const uint64_t num = parse_line_as_number(line);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
export uint64_t get_meminfo() {
|
||||
uint64_t get_meminfo() {
|
||||
return meminfo_parse(std::ifstream("/proc/meminfo")) * 1024;
|
||||
}
|
||||
|
||||
|
@ -60,7 +53,7 @@ PlayerctlPlayer* init_playerctl() {
|
|||
return nullptr;
|
||||
|
||||
// Get the first player
|
||||
const auto player_name =
|
||||
PlayerctlPlayerName* player_name =
|
||||
static_cast<PlayerctlPlayerName*>(available_players->data);
|
||||
|
||||
// Create the player
|
||||
|
@ -80,10 +73,8 @@ PlayerctlPlayer* init_playerctl() {
|
|||
return current_player;
|
||||
}
|
||||
|
||||
export string get_nowplaying() {
|
||||
if (PlayerctlPlayer* current_player = init_playerctl()) {
|
||||
string get_nowplaying() {
|
||||
if (PlayerctlPlayer* current_player = init_playerctl())
|
||||
return playerctl_player_get_title(current_player, nullptr);
|
||||
}
|
||||
|
||||
return "Could not get now playing info";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue