pushing this cuz i need to
This commit is contained in:
parent
37a93c57ea
commit
a24f19d16b
6 changed files with 189 additions and 112 deletions
78
src/main.cpp
78
src/main.cpp
|
@ -1,11 +1,13 @@
|
|||
#include "os/os.h"
|
||||
#include <boost/json/src.hpp>
|
||||
#include <cpr/cpr.h>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include <playerctl/playerctl.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <toml++/toml.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
using fmt::format;
|
||||
using fmt::formatter;
|
||||
|
@ -27,74 +29,6 @@ template <> struct formatter<b_to_gib> : formatter<double> {
|
|||
}
|
||||
};
|
||||
|
||||
uint64_t parse_line_as_number(const string &input) {
|
||||
// Find the first number
|
||||
string::size_type start = 0;
|
||||
|
||||
// Skip leading non-numbers
|
||||
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]))
|
||||
;
|
||||
|
||||
// Return the substring containing the number
|
||||
return std::stoul(input.substr(start, end - start));
|
||||
}
|
||||
|
||||
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"))
|
||||
;
|
||||
|
||||
// Parse the number from the line
|
||||
const auto num = parse_line_as_number(line);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
PlayerctlPlayer *init_playerctl() {
|
||||
// Create a player manager
|
||||
PlayerctlPlayerManager *const player_manager =
|
||||
playerctl_player_manager_new(nullptr);
|
||||
|
||||
// Create an empty player list
|
||||
GList *available_players = nullptr;
|
||||
|
||||
// Get the list of available players and put it in the player list
|
||||
g_object_get(player_manager, "player-names", &available_players, nullptr);
|
||||
|
||||
// If no players are available, return nullptr
|
||||
if (!available_players)
|
||||
return nullptr;
|
||||
|
||||
// Get the first player
|
||||
const auto player_name =
|
||||
static_cast<PlayerctlPlayerName *>(available_players->data);
|
||||
|
||||
// Create the player
|
||||
PlayerctlPlayer *const current_player =
|
||||
playerctl_player_new_from_name(player_name, nullptr);
|
||||
|
||||
// If no player is available, return nullptr
|
||||
if (!current_player)
|
||||
return nullptr;
|
||||
|
||||
// Manage the player
|
||||
playerctl_player_manager_manage_player(player_manager, current_player);
|
||||
|
||||
// Unref the player
|
||||
g_object_unref(current_player);
|
||||
|
||||
return current_player;
|
||||
}
|
||||
|
||||
enum date_num { Ones, Twos, Threes, Default };
|
||||
|
||||
date_num parse_date(string const &inString) {
|
||||
|
@ -117,7 +51,7 @@ boost::json::object get_weather() {
|
|||
Response r = Get(Url{format("https://api.openweathermap.org/data/2.5/"
|
||||
"weather?lat={}&lon={}&appid={}&units={}",
|
||||
"39.9537", "-74.1979",
|
||||
"00000000000000000000000000000000", "imperial")});
|
||||
"be387ee0e0d79c03368c52e0e3fe4f5b", "imperial")});
|
||||
|
||||
value json = parse(r.text);
|
||||
|
||||
|
@ -129,16 +63,18 @@ int main() {
|
|||
|
||||
const char *name = config["general"]["name"].value_or(getlogin());
|
||||
|
||||
#ifdef __linux__
|
||||
if (config["playerctl"]["enable"].value_or(false)) {
|
||||
if (PlayerctlPlayer *current_player = init_playerctl()) {
|
||||
gchar *song_title = playerctl_player_get_title(current_player, nullptr);
|
||||
fmt::println("Now playing: {}", song_title);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
fmt::println("Hello {}!", name);
|
||||
|
||||
const uint64_t meminfo = meminfo_parse(std::ifstream("/proc/meminfo")) * 1024;
|
||||
const uint64_t meminfo = get_meminfo();
|
||||
|
||||
fmt::println("{:.2f}", b_to_gib{meminfo});
|
||||
|
||||
|
|
77
src/os/linux.cpp
Normal file
77
src/os/linux.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include "os.h"
|
||||
#include <fstream>
|
||||
#include <playerctl/playerctl.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
uint64_t parse_line_as_number(const string &input) {
|
||||
// Find the first number
|
||||
string::size_type start = 0;
|
||||
|
||||
// Skip leading non-numbers
|
||||
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]))
|
||||
;
|
||||
|
||||
// Return the substring containing the number
|
||||
return std::stoul(input.substr(start, end - start));
|
||||
}
|
||||
|
||||
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"))
|
||||
;
|
||||
|
||||
// Parse the number from the line
|
||||
const auto num = parse_line_as_number(line);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
uint64_t get_meminfo() {
|
||||
return meminfo_parse(std::ifstream("/proc/meminfo")) * 1024;
|
||||
}
|
||||
|
||||
PlayerctlPlayer *init_playerctl() {
|
||||
// Create a player manager
|
||||
PlayerctlPlayerManager *const player_manager =
|
||||
playerctl_player_manager_new(nullptr);
|
||||
|
||||
// Create an empty player list
|
||||
GList *available_players = nullptr;
|
||||
|
||||
// Get the list of available players and put it in the player list
|
||||
g_object_get(player_manager, "player-names", &available_players, nullptr);
|
||||
|
||||
// If no players are available, return nullptr
|
||||
if (!available_players)
|
||||
return nullptr;
|
||||
|
||||
// Get the first player
|
||||
const auto player_name =
|
||||
static_cast<PlayerctlPlayerName *>(available_players->data);
|
||||
|
||||
// Create the player
|
||||
PlayerctlPlayer *const current_player =
|
||||
playerctl_player_new_from_name(player_name, nullptr);
|
||||
|
||||
// If no player is available, return nullptr
|
||||
if (!current_player)
|
||||
return nullptr;
|
||||
|
||||
// Manage the player
|
||||
playerctl_player_manager_manage_player(player_manager, current_player);
|
||||
|
||||
// Unref the player
|
||||
g_object_unref(current_player);
|
||||
|
||||
return current_player;
|
||||
}
|
11
src/os/macos.cpp
Normal file
11
src/os/macos.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "os.h"
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
uint64_t get_meminfo() {
|
||||
uint64_t mem = 0;
|
||||
size_t size = sizeof(mem);
|
||||
|
||||
sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
|
||||
|
||||
return mem;
|
||||
}
|
7
src/os/os.h
Normal file
7
src/os/os.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
uint64_t get_meminfo();
|
||||
string get_nowplaying();
|
Loading…
Add table
Add a link
Reference in a new issue