fixes and macos stuff

This commit is contained in:
Mars 2025-04-24 13:01:16 -04:00
parent 9695ceec8a
commit 801a8d1754
Signed by: pupbrained
GPG key ID: 874E22DF2F9DFCB5
10 changed files with 108 additions and 115 deletions

View file

@ -9,6 +9,7 @@ project(
'default_library=static', 'default_library=static',
'buildtype=debugoptimized', 'buildtype=debugoptimized',
'b_vscrt=mt', 'b_vscrt=mt',
'b_lto=true',
'warning_level=3', 'warning_level=3',
], ],
) )
@ -24,6 +25,7 @@ common_warning_flags = [
'-Wno-c++20-extensions', '-Wno-c++20-extensions',
'-Wno-c++98-compat', '-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic', '-Wno-c++98-compat-pedantic',
'-Wno-covered-switch-default',
'-Wno-disabled-macro-expansion', '-Wno-disabled-macro-expansion',
'-Wno-missing-prototypes', '-Wno-missing-prototypes',
'-Wno-padded', '-Wno-padded',

View file

@ -1,4 +1,3 @@
#include <cstdlib>
#include <filesystem> #include <filesystem>
#include <stdexcept> #include <stdexcept>

View file

@ -39,7 +39,7 @@ namespace {
DEBUG_LOG("Reading from cache file..."); DEBUG_LOG("Reading from cache file...");
try { try {
const String content((std::istreambuf_iterator(ifs)), std::istreambuf_iterator<char>()); const String content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
WeatherOutput result; WeatherOutput result;
if (const glz::error_ctx errc = glz::read<glaze_opts>(result, content); errc.ec != glz::error_code::none) if (const glz::error_ctx errc = glz::read<glaze_opts>(result, content); errc.ec != glz::error_code::none)
@ -79,7 +79,9 @@ namespace {
std::error_code errc; std::error_code errc;
fs::rename(tempPath, *cachePath, errc); fs::rename(tempPath, *cachePath, errc);
if (errc) { if (errc) {
fs::remove(tempPath, errc); if (!fs::remove(tempPath, errc))
DEBUG_LOG("Failed to remove temp file: {}", errc.message());
return Err("Failed to replace cache file: " + errc.message()); return Err("Failed to replace cache file: " + errc.message());
} }

View file

@ -8,7 +8,7 @@
struct Condition { struct Condition {
String description; String description;
struct glaze { struct [[maybe_unused]] glaze {
using T = Condition; using T = Condition;
static constexpr glz::detail::Object value = glz::object("description", &T::description); static constexpr glz::detail::Object value = glz::object("description", &T::description);
@ -18,7 +18,7 @@ struct Condition {
struct Main { struct Main {
f64 temp; f64 temp;
struct glaze { struct [[maybe_unused]] glaze {
using T = Main; using T = Main;
static constexpr glz::detail::Object value = glz::object("temp", &T::temp); static constexpr glz::detail::Object value = glz::object("temp", &T::temp);
@ -36,7 +36,7 @@ struct WeatherOutput {
Vec<Condition> weather; Vec<Condition> weather;
usize dt; usize dt;
struct glaze { struct [[maybe_unused]] glaze {
using T = WeatherOutput; using T = WeatherOutput;
static constexpr glz::detail::Object value = static constexpr glz::detail::Object value =

View file

@ -34,6 +34,11 @@ fn SystemData::fetchSystemData(const Config& config) -> SystemData {
.mem_info = os::GetMemInfo(), .mem_info = os::GetMemInfo(),
.desktop_environment = os::GetDesktopEnvironment(), .desktop_environment = os::GetDesktopEnvironment(),
.window_manager = os::GetWindowManager(), .window_manager = os::GetWindowManager(),
.now_playing = {},
.weather_info = {},
.disk_used = {},
.disk_total = {},
.shell = {},
}; };
auto diskShell = std::async(std::launch::async, [] { auto diskShell = std::async(std::launch::async, [] {

View file

@ -11,12 +11,11 @@
#include "core/system_data.h" #include "core/system_data.h"
#include "os/os.h" #include "os/os.h"
constexpr inline bool SHOW_ICONS = true;
namespace ui { namespace ui {
using ftxui::Color; using ftxui::Color;
constexpr i32 MAX_PARAGRAPH_LENGTH = 30; static constexpr inline bool SHOW_ICONS = true;
static constexpr i32 MAX_PARAGRAPH_LENGTH = 30;
// Color themes // Color themes
struct Theme { struct Theme {
@ -24,34 +23,32 @@ namespace ui {
Color::Palette16 label; Color::Palette16 label;
Color::Palette16 value; Color::Palette16 value;
Color::Palette16 border; Color::Palette16 border;
Color::Palette16 accent;
}; };
constexpr Theme DEFAULT_THEME = { static constexpr Theme DEFAULT_THEME = {
.icon = Color::Cyan, .icon = Color::Cyan,
.label = Color::Yellow, .label = Color::Yellow,
.value = Color::White, .value = Color::White,
.border = Color::GrayLight, .border = Color::GrayLight,
.accent = Color::Magenta,
}; };
struct Icons { struct Icons {
std::string_view user; [[maybe_unused]] StringView user;
std::string_view palette; [[maybe_unused]] StringView palette;
std::string_view calendar; [[maybe_unused]] StringView calendar;
std::string_view host; [[maybe_unused]] StringView host;
std::string_view kernel; [[maybe_unused]] StringView kernel;
std::string_view os; [[maybe_unused]] StringView os;
std::string_view memory; [[maybe_unused]] StringView memory;
std::string_view weather; [[maybe_unused]] StringView weather;
std::string_view music; [[maybe_unused]] StringView music;
std::string_view disk; [[maybe_unused]] StringView disk;
std::string_view shell; [[maybe_unused]] StringView shell;
std::string_view desktop; [[maybe_unused]] StringView desktop;
std::string_view window_manager; [[maybe_unused]] StringView window_manager;
}; };
constexpr Icons EMPTY_ICONS = { static constexpr Icons EMPTY_ICONS = {
.user = "", .user = "",
.palette = "", .palette = "",
.calendar = "", .calendar = "",
@ -67,8 +64,7 @@ namespace ui {
.window_manager = "", .window_manager = "",
}; };
// Using your original icons static constexpr Icons NERD_ICONS = {
constexpr Icons NERD_ICONS = {
.user = "", .user = "",
.palette = "", .palette = "",
.calendar = "", .calendar = "",
@ -103,32 +99,27 @@ namespace {
const bool nowPlayingEnabled = config.now_playing.enabled; const bool nowPlayingEnabled = config.now_playing.enabled;
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, deIcon, wmIcon] =
// ReSharper disable once CppDFAUnreachableCode ui::SHOW_ICONS ? ui::NERD_ICONS : ui::EMPTY_ICONS;
SHOW_ICONS ? ui::NERD_ICONS : ui::EMPTY_ICONS;
Elements content; Elements content;
content.push_back(text(String(userIcon) + "Hello " + name + "! ") | bold | color(Color::Cyan)); content.push_back(text(String(userIcon) + "Hello " + name + "! ") | bold | color(Color::Cyan));
content.push_back(separator() | color(ui::DEFAULT_THEME.border)); content.push_back(separator() | color(ui::DEFAULT_THEME.border));
content.push_back(hbox( content.push_back(hbox({
{
text(String(paletteIcon)) | color(ui::DEFAULT_THEME.icon), text(String(paletteIcon)) | color(ui::DEFAULT_THEME.icon),
CreateColorCircles(), CreateColorCircles(),
} }));
));
content.push_back(separator() | color(ui::DEFAULT_THEME.border)); content.push_back(separator() | color(ui::DEFAULT_THEME.border));
// Helper function for aligned rows // Helper function for aligned rows
fn createRow = [&](const auto& icon, const auto& label, const auto& value) { fn createRow = [&](const auto& icon, const auto& label, const auto& value) {
return hbox( return hbox({
{
text(String(icon)) | color(ui::DEFAULT_THEME.icon), text(String(icon)) | color(ui::DEFAULT_THEME.icon),
text(String(static_cast<CStr>(label))) | color(ui::DEFAULT_THEME.label), text(String(static_cast<CStr>(label))) | color(ui::DEFAULT_THEME.label),
filler(), filler(),
text(String(value)) | color(ui::DEFAULT_THEME.value), text(String(value)) | color(ui::DEFAULT_THEME.value),
text(" "), text(" "),
} });
);
}; };
// System info rows // System info rows
@ -139,39 +130,31 @@ namespace {
const WeatherOutput& weatherInfo = data.weather_info.value(); const WeatherOutput& weatherInfo = data.weather_info.value();
if (weather.show_town_name) if (weather.show_town_name)
content.push_back(hbox( content.push_back(hbox({
{
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon), text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label), text("Weather") | color(ui::DEFAULT_THEME.label),
filler(), filler(),
hbox( hbox({
{
text(std::format("{}°F ", std::lround(weatherInfo.main.temp))), text(std::format("{}°F ", std::lround(weatherInfo.main.temp))),
text("in "), text("in "),
text(weatherInfo.name), text(weatherInfo.name),
text(" "), text(" "),
} }) |
) |
color(ui::DEFAULT_THEME.value), color(ui::DEFAULT_THEME.value),
} }));
));
else else
content.push_back(hbox( content.push_back(hbox({
{
text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon), text(String(weatherIcon)) | color(ui::DEFAULT_THEME.icon),
text("Weather") | color(ui::DEFAULT_THEME.label), text("Weather") | color(ui::DEFAULT_THEME.label),
filler(), filler(),
hbox( hbox({
{
text(std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)), text(std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)),
text(" "), text(" "),
} }) |
) |
color(ui::DEFAULT_THEME.value), color(ui::DEFAULT_THEME.value),
} }));
));
} }
content.push_back(separator() | color(ui::DEFAULT_THEME.border)); content.push_back(separator() | color(ui::DEFAULT_THEME.border));
@ -213,16 +196,14 @@ namespace {
const String& npText = *nowPlayingResult; const String& npText = *nowPlayingResult;
content.push_back(separator() | color(ui::DEFAULT_THEME.border)); content.push_back(separator() | color(ui::DEFAULT_THEME.border));
content.push_back(hbox( content.push_back(hbox({
{
text(String(musicIcon)) | color(ui::DEFAULT_THEME.icon), text(String(musicIcon)) | color(ui::DEFAULT_THEME.icon),
text("Playing") | color(ui::DEFAULT_THEME.label), text("Playing") | color(ui::DEFAULT_THEME.label),
text(" "), text(" "),
filler(), filler(),
paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, ui::MAX_PARAGRAPH_LENGTH), paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, ui::MAX_PARAGRAPH_LENGTH),
text(" "), text(" "),
} }));
));
} else { } else {
const NowPlayingError& error = nowPlayingResult.error(); const NowPlayingError& error = nowPlayingResult.error();
@ -230,6 +211,7 @@ namespace {
switch (std::get<NowPlayingCode>(error)) { switch (std::get<NowPlayingCode>(error)) {
case NowPlayingCode::NoPlayers: DEBUG_LOG("No players found"); break; case NowPlayingCode::NoPlayers: DEBUG_LOG("No players found"); break;
case NowPlayingCode::NoActivePlayer: DEBUG_LOG("No active player found"); break; case NowPlayingCode::NoActivePlayer: DEBUG_LOG("No active player found"); break;
default: std::unreachable();
} }
#ifdef _WIN32 #ifdef _WIN32

View file

@ -9,7 +9,7 @@
#include "os.h" #include "os.h"
#include "src/util/types.h" #include "src/util/types.h"
fn GetMemInfo() -> Result<u64, String> { fn os::GetMemInfo() -> Result<u64, String> {
u64 mem = 0; u64 mem = 0;
usize size = sizeof(mem); usize size = sizeof(mem);
@ -19,15 +19,15 @@ fn GetMemInfo() -> Result<u64, String> {
return mem; return mem;
} }
fn GetNowPlaying() -> Result<String, NowPlayingError> { return GetCurrentPlayingInfo(); } fn os::GetNowPlaying() -> Result<String, NowPlayingError> { return GetCurrentPlayingInfo(); }
fn GetOSVersion() -> Result<String, String> { return GetMacOSVersion(); } fn os::GetOSVersion() -> Result<String, String> { return GetMacOSVersion(); }
fn GetDesktopEnvironment() -> Option<String> { return None; } fn os::GetDesktopEnvironment() -> Option<String> { return None; }
fn GetWindowManager() -> String { return "Yabai"; } fn os::GetWindowManager() -> String { return "Yabai"; }
fn GetKernelVersion() -> String { fn os::GetKernelVersion() -> String {
std::array<char, 256> kernelVersion {}; std::array<char, 256> kernelVersion {};
usize kernelVersionLen = sizeof(kernelVersion); usize kernelVersionLen = sizeof(kernelVersion);
@ -35,7 +35,7 @@ fn GetKernelVersion() -> String {
return kernelVersion.data(); return kernelVersion.data();
} }
fn GetHost() -> String { fn os::GetHost() -> String {
std::array<char, 256> hwModel {}; std::array<char, 256> hwModel {};
size_t hwModelLen = sizeof(hwModel); size_t hwModelLen = sizeof(hwModel);
@ -195,7 +195,7 @@ fn GetHost() -> String {
return String(modelNameByHwModel[hwModel.data()]); return String(modelNameByHwModel[hwModel.data()]);
} }
fn GetDiskUsage() -> std::pair<u64, u64> { fn os::GetDiskUsage() -> std::pair<u64, u64> {
struct statvfs vfs; struct statvfs vfs;
if (statvfs("/", &vfs) != 0) if (statvfs("/", &vfs) != 0)
@ -204,6 +204,6 @@ fn GetDiskUsage() -> std::pair<u64, u64> {
return { (vfs.f_blocks - vfs.f_bfree) * vfs.f_frsize, vfs.f_blocks * vfs.f_frsize }; return { (vfs.f_blocks - vfs.f_bfree) * vfs.f_frsize, vfs.f_blocks * vfs.f_frsize };
} }
fn GetShell() -> String { return ""; } fn os::GetShell() -> String { return ""; }
#endif #endif

View file

@ -95,15 +95,15 @@ extern "C++" {
return; return;
} }
NSDictionary* metadata = *metadataResult; const NSDictionary* const metadata = *metadataResult;
if (!metadata) { if (!metadata) {
result = std::unexpected(NowPlayingError { NowPlayingCode::NoPlayers }); result = std::unexpected(NowPlayingError { NowPlayingCode::NoPlayers });
dispatch_semaphore_signal(semaphore); dispatch_semaphore_signal(semaphore);
return; return;
} }
NSString* title = metadata[@"kMRMediaRemoteNowPlayingInfoTitle"]; const NSString* const title = metadata[@"kMRMediaRemoteNowPlayingInfoTitle"];
NSString* artist = metadata[@"kMRMediaRemoteNowPlayingInfoArtist"]; const NSString* const artist = metadata[@"kMRMediaRemoteNowPlayingInfoArtist"];
if (!title && !artist) if (!title && !artist)
result = std::unexpected(NowPlayingError { "No metadata" }); result = std::unexpected(NowPlayingError { "No metadata" });

View file

@ -55,3 +55,4 @@ namespace os {
*/ */
fn GetDiskUsage() -> Pair<u64, u64>; fn GetDiskUsage() -> Pair<u64, u64>;
} }

View file

@ -28,24 +28,26 @@ namespace term {
return static_cast<Emphasis>(static_cast<int>(emphA) | static_cast<int>(emphB)); return static_cast<Emphasis>(static_cast<int>(emphA) | static_cast<int>(emphB));
} }
// clang-format off
enum class Color : u8 { enum class Color : u8 {
black = 30, black [[maybe_unused]] = 30,
red = 31, red [[maybe_unused]] = 31,
green = 32, green [[maybe_unused]] = 32,
yellow = 33, yellow [[maybe_unused]] = 33,
blue = 34, blue [[maybe_unused]] = 34,
magenta = 35, magenta [[maybe_unused]] = 35,
cyan = 36, cyan [[maybe_unused]] = 36,
white = 37, white [[maybe_unused]] = 37,
bright_black = 90, bright_black [[maybe_unused]] = 90,
bright_red = 91, bright_red [[maybe_unused]] = 91,
bright_green = 92, bright_green [[maybe_unused]] = 92,
bright_yellow = 93, bright_yellow [[maybe_unused]] = 93,
bright_blue = 94, bright_blue [[maybe_unused]] = 94,
bright_magenta = 95, bright_magenta [[maybe_unused]] = 95,
bright_cyan = 96, bright_cyan [[maybe_unused]] = 96,
bright_white = 97 bright_white [[maybe_unused]] = 97
}; };
// clang-format on
struct FgColor { struct FgColor {
Color col; Color col;