fixes and macos stuff
This commit is contained in:
parent
9695ceec8a
commit
801a8d1754
10 changed files with 108 additions and 115 deletions
|
@ -9,6 +9,7 @@ project(
|
|||
'default_library=static',
|
||||
'buildtype=debugoptimized',
|
||||
'b_vscrt=mt',
|
||||
'b_lto=true',
|
||||
'warning_level=3',
|
||||
],
|
||||
)
|
||||
|
@ -24,6 +25,7 @@ common_warning_flags = [
|
|||
'-Wno-c++20-extensions',
|
||||
'-Wno-c++98-compat',
|
||||
'-Wno-c++98-compat-pedantic',
|
||||
'-Wno-covered-switch-default',
|
||||
'-Wno-disabled-macro-expansion',
|
||||
'-Wno-missing-prototypes',
|
||||
'-Wno-padded',
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace {
|
|||
DEBUG_LOG("Reading from cache file...");
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
fs::rename(tempPath, *cachePath, 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
struct Condition {
|
||||
String description;
|
||||
|
||||
struct glaze {
|
||||
struct [[maybe_unused]] glaze {
|
||||
using T = Condition;
|
||||
|
||||
static constexpr glz::detail::Object value = glz::object("description", &T::description);
|
||||
|
@ -18,7 +18,7 @@ struct Condition {
|
|||
struct Main {
|
||||
f64 temp;
|
||||
|
||||
struct glaze {
|
||||
struct [[maybe_unused]] glaze {
|
||||
using T = Main;
|
||||
|
||||
static constexpr glz::detail::Object value = glz::object("temp", &T::temp);
|
||||
|
@ -36,7 +36,7 @@ struct WeatherOutput {
|
|||
Vec<Condition> weather;
|
||||
usize dt;
|
||||
|
||||
struct glaze {
|
||||
struct [[maybe_unused]] glaze {
|
||||
using T = WeatherOutput;
|
||||
|
||||
static constexpr glz::detail::Object value =
|
||||
|
|
|
@ -34,6 +34,11 @@ fn SystemData::fetchSystemData(const Config& config) -> SystemData {
|
|||
.mem_info = os::GetMemInfo(),
|
||||
.desktop_environment = os::GetDesktopEnvironment(),
|
||||
.window_manager = os::GetWindowManager(),
|
||||
.now_playing = {},
|
||||
.weather_info = {},
|
||||
.disk_used = {},
|
||||
.disk_total = {},
|
||||
.shell = {},
|
||||
};
|
||||
|
||||
auto diskShell = std::async(std::launch::async, [] {
|
||||
|
|
140
src/main.cpp
140
src/main.cpp
|
@ -11,12 +11,11 @@
|
|||
#include "core/system_data.h"
|
||||
#include "os/os.h"
|
||||
|
||||
constexpr inline bool SHOW_ICONS = true;
|
||||
|
||||
namespace ui {
|
||||
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
|
||||
struct Theme {
|
||||
|
@ -24,34 +23,32 @@ namespace ui {
|
|||
Color::Palette16 label;
|
||||
Color::Palette16 value;
|
||||
Color::Palette16 border;
|
||||
Color::Palette16 accent;
|
||||
};
|
||||
|
||||
constexpr Theme DEFAULT_THEME = {
|
||||
static constexpr Theme DEFAULT_THEME = {
|
||||
.icon = Color::Cyan,
|
||||
.label = Color::Yellow,
|
||||
.value = Color::White,
|
||||
.border = Color::GrayLight,
|
||||
.accent = Color::Magenta,
|
||||
};
|
||||
|
||||
struct Icons {
|
||||
std::string_view user;
|
||||
std::string_view palette;
|
||||
std::string_view calendar;
|
||||
std::string_view host;
|
||||
std::string_view kernel;
|
||||
std::string_view os;
|
||||
std::string_view memory;
|
||||
std::string_view weather;
|
||||
std::string_view music;
|
||||
std::string_view disk;
|
||||
std::string_view shell;
|
||||
std::string_view desktop;
|
||||
std::string_view window_manager;
|
||||
[[maybe_unused]] StringView user;
|
||||
[[maybe_unused]] StringView palette;
|
||||
[[maybe_unused]] StringView calendar;
|
||||
[[maybe_unused]] StringView host;
|
||||
[[maybe_unused]] StringView kernel;
|
||||
[[maybe_unused]] StringView os;
|
||||
[[maybe_unused]] StringView memory;
|
||||
[[maybe_unused]] StringView weather;
|
||||
[[maybe_unused]] StringView music;
|
||||
[[maybe_unused]] StringView disk;
|
||||
[[maybe_unused]] StringView shell;
|
||||
[[maybe_unused]] StringView desktop;
|
||||
[[maybe_unused]] StringView window_manager;
|
||||
};
|
||||
|
||||
constexpr Icons EMPTY_ICONS = {
|
||||
static constexpr Icons EMPTY_ICONS = {
|
||||
.user = "",
|
||||
.palette = "",
|
||||
.calendar = "",
|
||||
|
@ -67,8 +64,7 @@ namespace ui {
|
|||
.window_manager = "",
|
||||
};
|
||||
|
||||
// Using your original icons
|
||||
constexpr Icons NERD_ICONS = {
|
||||
static constexpr Icons NERD_ICONS = {
|
||||
.user = " ",
|
||||
.palette = " ",
|
||||
.calendar = " ",
|
||||
|
@ -103,32 +99,27 @@ namespace {
|
|||
const bool nowPlayingEnabled = config.now_playing.enabled;
|
||||
|
||||
const auto& [userIcon, paletteIcon, calendarIcon, hostIcon, kernelIcon, osIcon, memoryIcon, weatherIcon, musicIcon, diskIcon, shellIcon, deIcon, wmIcon] =
|
||||
// ReSharper disable once CppDFAUnreachableCode
|
||||
SHOW_ICONS ? ui::NERD_ICONS : ui::EMPTY_ICONS;
|
||||
ui::SHOW_ICONS ? ui::NERD_ICONS : ui::EMPTY_ICONS;
|
||||
|
||||
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 auto& icon, const auto& label, const auto& value) {
|
||||
return hbox(
|
||||
{
|
||||
text(String(icon)) | color(ui::DEFAULT_THEME.icon),
|
||||
text(String(static_cast<CStr>(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(static_cast<CStr>(label))) | color(ui::DEFAULT_THEME.label),
|
||||
filler(),
|
||||
text(String(value)) | color(ui::DEFAULT_THEME.value),
|
||||
text(" "),
|
||||
});
|
||||
};
|
||||
|
||||
// System info rows
|
||||
|
@ -139,39 +130,31 @@ namespace {
|
|||
const WeatherOutput& weatherInfo = data.weather_info.value();
|
||||
|
||||
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(),
|
||||
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),
|
||||
}));
|
||||
}
|
||||
|
||||
content.push_back(separator() | color(ui::DEFAULT_THEME.border));
|
||||
|
@ -213,16 +196,14 @@ namespace {
|
|||
const String& npText = *nowPlayingResult;
|
||||
|
||||
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(" "),
|
||||
}
|
||||
));
|
||||
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 {
|
||||
const NowPlayingError& error = nowPlayingResult.error();
|
||||
|
||||
|
@ -230,6 +211,7 @@ namespace {
|
|||
switch (std::get<NowPlayingCode>(error)) {
|
||||
case NowPlayingCode::NoPlayers: DEBUG_LOG("No players found"); break;
|
||||
case NowPlayingCode::NoActivePlayer: DEBUG_LOG("No active player found"); break;
|
||||
default: std::unreachable();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "os.h"
|
||||
#include "src/util/types.h"
|
||||
|
||||
fn GetMemInfo() -> Result<u64, String> {
|
||||
fn os::GetMemInfo() -> Result<u64, String> {
|
||||
u64 mem = 0;
|
||||
usize size = sizeof(mem);
|
||||
|
||||
|
@ -19,15 +19,15 @@ fn GetMemInfo() -> Result<u64, String> {
|
|||
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 {};
|
||||
usize kernelVersionLen = sizeof(kernelVersion);
|
||||
|
||||
|
@ -35,7 +35,7 @@ fn GetKernelVersion() -> String {
|
|||
return kernelVersion.data();
|
||||
}
|
||||
|
||||
fn GetHost() -> String {
|
||||
fn os::GetHost() -> String {
|
||||
std::array<char, 256> hwModel {};
|
||||
size_t hwModelLen = sizeof(hwModel);
|
||||
|
||||
|
@ -195,7 +195,7 @@ fn GetHost() -> String {
|
|||
return String(modelNameByHwModel[hwModel.data()]);
|
||||
}
|
||||
|
||||
fn GetDiskUsage() -> std::pair<u64, u64> {
|
||||
fn os::GetDiskUsage() -> std::pair<u64, u64> {
|
||||
struct statvfs vfs;
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
fn GetShell() -> String { return ""; }
|
||||
fn os::GetShell() -> String { return ""; }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -95,15 +95,15 @@ extern "C++" {
|
|||
return;
|
||||
}
|
||||
|
||||
NSDictionary* metadata = *metadataResult;
|
||||
const NSDictionary* const metadata = *metadataResult;
|
||||
if (!metadata) {
|
||||
result = std::unexpected(NowPlayingError { NowPlayingCode::NoPlayers });
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
return;
|
||||
}
|
||||
|
||||
NSString* title = metadata[@"kMRMediaRemoteNowPlayingInfoTitle"];
|
||||
NSString* artist = metadata[@"kMRMediaRemoteNowPlayingInfoArtist"];
|
||||
const NSString* const title = metadata[@"kMRMediaRemoteNowPlayingInfoTitle"];
|
||||
const NSString* const artist = metadata[@"kMRMediaRemoteNowPlayingInfoArtist"];
|
||||
|
||||
if (!title && !artist)
|
||||
result = std::unexpected(NowPlayingError { "No metadata" });
|
||||
|
|
|
@ -55,3 +55,4 @@ namespace os {
|
|||
*/
|
||||
fn GetDiskUsage() -> Pair<u64, u64>;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,24 +28,26 @@ namespace term {
|
|||
return static_cast<Emphasis>(static_cast<int>(emphA) | static_cast<int>(emphB));
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
enum class Color : u8 {
|
||||
black = 30,
|
||||
red = 31,
|
||||
green = 32,
|
||||
yellow = 33,
|
||||
blue = 34,
|
||||
magenta = 35,
|
||||
cyan = 36,
|
||||
white = 37,
|
||||
bright_black = 90,
|
||||
bright_red = 91,
|
||||
bright_green = 92,
|
||||
bright_yellow = 93,
|
||||
bright_blue = 94,
|
||||
bright_magenta = 95,
|
||||
bright_cyan = 96,
|
||||
bright_white = 97
|
||||
black [[maybe_unused]] = 30,
|
||||
red [[maybe_unused]] = 31,
|
||||
green [[maybe_unused]] = 32,
|
||||
yellow [[maybe_unused]] = 33,
|
||||
blue [[maybe_unused]] = 34,
|
||||
magenta [[maybe_unused]] = 35,
|
||||
cyan [[maybe_unused]] = 36,
|
||||
white [[maybe_unused]] = 37,
|
||||
bright_black [[maybe_unused]] = 90,
|
||||
bright_red [[maybe_unused]] = 91,
|
||||
bright_green [[maybe_unused]] = 92,
|
||||
bright_yellow [[maybe_unused]] = 93,
|
||||
bright_blue [[maybe_unused]] = 94,
|
||||
bright_magenta [[maybe_unused]] = 95,
|
||||
bright_cyan [[maybe_unused]] = 96,
|
||||
bright_white [[maybe_unused]] = 97
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
struct FgColor {
|
||||
Color col;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue