This commit is contained in:
Mars 2025-05-01 02:06:05 -04:00
parent 3ad961a571
commit 3b16fee5f4
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
28 changed files with 1242 additions and 1047 deletions

View file

@ -6,12 +6,12 @@
#include <ftxui/screen/screen.hpp> // ftxui::{Screen, Dimension::Full}
#include <ranges> // std::ranges::{iota, to, transform}
#include "src/config/config.hpp"
#include "src/config/weather.hpp"
#include "config/config.hpp"
#include "core/system_data.hpp"
#include "core/util/logging.hpp"
#include "os/os.hpp"
#include "src/core/system_data.hpp"
#include "src/core/util/defs.hpp"
#include "src/core/util/logging.hpp"
#include "src/core/util/types.hpp"
namespace ui {
using ftxui::Color;
@ -46,56 +46,60 @@ namespace ui {
StringView music;
StringView disk;
StringView shell;
StringView package;
StringView desktop;
StringView window_manager;
StringView windowManager;
};
[[maybe_unused]] static constexpr Icons NONE = {
.user = "",
.palette = "",
.calendar = "",
.host = "",
.kernel = "",
.os = "",
.memory = "",
.weather = "",
.music = "",
.disk = "",
.shell = "",
.desktop = "",
.window_manager = "",
.user = "",
.palette = "",
.calendar = "",
.host = "",
.kernel = "",
.os = "",
.memory = "",
.weather = "",
.music = "",
.disk = "",
.shell = "",
.package = "",
.desktop = "",
.windowManager = "",
};
[[maybe_unused]] static constexpr Icons NERD = {
.user = "",
.palette = "",
.calendar = "",
.host = " 󰌢 ",
.kernel = "",
.os = "",
.memory = "",
.weather = "",
.music = "",
.disk = " 󰋊 ",
.shell = "",
.desktop = " 󰇄 ",
.window_manager = "  ",
.user = "",
.palette = "",
.calendar = "",
.host = " 󰌢 ",
.kernel = "",
.os = "",
.memory = "",
.weather = "",
.music = "",
.disk = " 󰋊 ",
.shell = "",
.package = " 󰏖 ",
.desktop = " 󰇄 ",
.windowManager = "  ",
};
[[maybe_unused]] static constexpr Icons EMOJI = {
.user = " 👤 ",
.palette = " 🎨 ",
.calendar = " 📅 ",
.host = " 💻 ",
.kernel = " 🫀 ",
.os = " 🤖 ",
.memory = " 🧠 ",
.weather = " 🌈 ",
.music = " 🎵 ",
.disk = " 💾 ",
.shell = " 💲 ",
.desktop = " 🖥️ ",
.window_manager = " 🪟 ",
.user = " 👤 ",
.palette = " 🎨 ",
.calendar = " 📅 ",
.host = " 💻 ",
.kernel = " 🫀 ",
.os = " 🤖 ",
.memory = " 🧠 ",
.weather = " 🌈 ",
.music = " 🎵 ",
.disk = " 💾 ",
.shell = " 💲 ",
.package = " 📦 ",
.desktop = " 🖥️ ",
.windowManager = " 🪟 ",
};
static constexpr inline Icons ICON_TYPE = NERD;
@ -114,80 +118,69 @@ namespace {
);
}
fn SystemInfoBox(const Config& config, const SystemData& data) -> Element {
fn SystemInfoBox(const Config& config, const os::SystemData& data) -> Element {
const String& name = config.general.name;
const Weather weather = config.weather;
const auto& [userIcon, paletteIcon, calendarIcon, hostIcon, kernelIcon, osIcon, memoryIcon, weatherIcon, musicIcon, diskIcon, shellIcon, deIcon, wmIcon] =
const auto& [userIcon, paletteIcon, calendarIcon, hostIcon, kernelIcon, osIcon, memoryIcon, weatherIcon, musicIcon, diskIcon, shellIcon, packageIcon, deIcon, wmIcon] =
ui::ICON_TYPE;
Elements content;
content.push_back(text(String(userIcon) + "Hello " + name + "! ") | bold | color(Color::Cyan));
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
content.push_back(hbox(
{
text(String(paletteIcon)) | color(ui::DEFAULT_THEME.icon),
CreateColorCircles(),
}
));
content.push_back(hbox({
text(String(paletteIcon)) | color(ui::DEFAULT_THEME.icon),
CreateColorCircles(),
}));
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
// Helper function for aligned rows
fn createRow = [&](const StringView& icon, const StringView& label, const StringView& value) { // NEW
return hbox(
{
text(String(icon)) | color(ui::DEFAULT_THEME.icon),
text(String(label)) | color(ui::DEFAULT_THEME.label),
filler(),
text(String(value)) | color(ui::DEFAULT_THEME.value),
text(" "),
}
);
return hbox({
text(String(icon)) | color(ui::DEFAULT_THEME.icon),
text(String(label)) | color(ui::DEFAULT_THEME.label),
filler(),
text(String(value)) | color(ui::DEFAULT_THEME.value),
text(" "),
});
};
// System info rows
content.push_back(createRow(calendarIcon, "Date", data.date));
// Weather row
if (weather.enabled && data.weather_info.has_value()) {
const weather::Output& weatherInfo = data.weather_info.value();
if (weather.enabled && data.weather) {
const weather::Output& weatherInfo = *data.weather;
if (weather.show_town_name)
content.push_back(hbox(
{
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label),
filler(),
if (weather.showTownName)
content.push_back(hbox({
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label),
filler(),
hbox(
{
text(std::format("{}°F ", std::lround(weatherInfo.main.temp))),
text("in "),
text(weatherInfo.name),
text(" "),
}
) |
color(ui::DEFAULT_THEME.value),
}
));
hbox({
text(std::format("{}°F ", std::lround(weatherInfo.main.temp))),
text("in "),
text(weatherInfo.name),
text(" "),
}) |
color(ui::DEFAULT_THEME.value),
}));
else
content.push_back(hbox(
{
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label),
filler(),
content.push_back(hbox({
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label),
filler(),
hbox(
{
text(std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)),
text(" "),
}
) |
color(ui::DEFAULT_THEME.value),
}
));
}
hbox({
text(std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)),
text(" "),
}) |
color(ui::DEFAULT_THEME.value),
}));
} else if (weather.enabled)
error_at(data.weather.error());
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
@ -196,62 +189,64 @@ namespace {
else
error_at(data.host.error());
if (data.kernel_version)
content.push_back(createRow(kernelIcon, "Kernel", *data.kernel_version));
if (data.kernelVersion)
content.push_back(createRow(kernelIcon, "Kernel", *data.kernelVersion));
else
error_at(data.kernel_version.error());
error_at(data.kernelVersion.error());
if (data.os_version)
content.push_back(createRow(String(osIcon), "OS", *data.os_version));
if (data.osVersion)
content.push_back(createRow(String(osIcon), "OS", *data.osVersion));
else
error_at(data.os_version.error());
error_at(data.osVersion.error());
if (data.mem_info)
content.push_back(createRow(memoryIcon, "RAM", std::format("{}", BytesToGiB { *data.mem_info })));
if (data.memInfo)
content.push_back(createRow(memoryIcon, "RAM", std::format("{}", BytesToGiB { *data.memInfo })));
else
error_at(data.mem_info.error());
error_at(data.memInfo.error());
if (data.disk_usage)
if (data.diskUsage)
content.push_back(createRow(
diskIcon,
"Disk",
std::format("{}/{}", BytesToGiB { data.disk_usage->used_bytes }, BytesToGiB { data.disk_usage->total_bytes })
std::format("{}/{}", BytesToGiB { data.diskUsage->used_bytes }, BytesToGiB { data.diskUsage->total_bytes })
));
else
error_at(data.disk_usage.error());
error_at(data.diskUsage.error());
if (data.shell)
content.push_back(createRow(shellIcon, "Shell", *data.shell));
else
error_at(data.shell.error());
if (data.packageCount)
content.push_back(createRow(packageIcon, "Packages", std::format("{}", *data.packageCount)));
else
error_at(data.packageCount.error());
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
if (data.desktop_environment && *data.desktop_environment != data.window_manager)
content.push_back(createRow(deIcon, "DE", *data.desktop_environment));
if (data.desktopEnv && *data.desktopEnv != data.windowMgr)
content.push_back(createRow(deIcon, "DE", *data.desktopEnv));
if (data.window_manager)
content.push_back(createRow(wmIcon, "WM", *data.window_manager));
if (data.windowMgr)
content.push_back(createRow(wmIcon, "WM", *data.windowMgr));
else
error_at(data.windowMgr.error());
if (config.now_playing.enabled && data.now_playing) {
if (const Result<MediaInfo, DraconisError>& nowPlayingResult = *data.now_playing) {
const MediaInfo& info = *nowPlayingResult;
if (config.nowPlaying.enabled && data.nowPlaying) {
const String title = data.nowPlaying->title.value_or("Unknown Title");
const String artist = data.nowPlaying->artist.value_or("Unknown Artist");
const String npText = artist + " - " + title;
const String title = info.title.value_or("Unknown Title");
const String artist = info.artist.value_or("Unknown Artist");
const String npText = artist + " - " + title;
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
content.push_back(hbox(
{
text(String(musicIcon)) | color(ui::DEFAULT_THEME.icon),
text("Playing") | color(ui::DEFAULT_THEME.label),
text(" "),
filler(),
paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, ui::MAX_PARAGRAPH_LENGTH),
text(" "),
}
));
} else
debug_at(nowPlayingResult.error());
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
content.push_back(hbox({
text(String(musicIcon)) | color(ui::DEFAULT_THEME.icon),
text("Playing") | color(ui::DEFAULT_THEME.label),
text(" "),
filler(),
paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, ui::MAX_PARAGRAPH_LENGTH),
text(" "),
}));
}
return vbox(content) | borderRounded | color(Color::White);
@ -259,17 +254,14 @@ namespace {
} // namespace
fn main() -> i32 {
using os::SystemData;
#ifdef _WIN32
winrt::init_apartment();
#endif
const Config& config = Config::getInstance();
const SystemData data = SystemData::fetchSystemData(config);
if (const Result<u64, DraconisError>& packageCount = os::GetPackageCount())
debug_log("{}", *packageCount);
else
error_at(packageCount.error());
const SystemData data = SystemData(config);
Element document = vbox({ hbox({ SystemInfoBox(config, data), filler() }) });