From 39a6a5cff088743622dfd6a198de6bffafbe4b05 Mon Sep 17 00:00:00 2001 From: pupbrained Date: Tue, 28 Jan 2025 20:58:20 -0500 Subject: [PATCH] uhgmasdgh --- src/main.cpp | 35 +++++++++++++++------------------ src/util/macros.h | 50 ++++++++++++----------------------------------- 2 files changed, 29 insertions(+), 56 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 16b50fb..555ed45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -59,7 +60,7 @@ namespace { fn CreateColorCircles() -> Element { Elements circles; for (int i = 0; i < 16; ++i) { - circles.push_back(text("◍") | color(Color::Palette256(i))); + circles.push_back(text("◯") | bold | color(Color::Palette256(i))); circles.push_back(text(" ")); } return hbox(circles); @@ -67,24 +68,24 @@ namespace { fn SystemInfoBox(const Config& config) -> Element { // Fetch data + const std::string& name = config.general.get().name.get(); std::string date = GetDate(); u64 memInfo = GetMemInfo(); std::string osVersion = GetOSVersion(); Weather weather = config.weather.get(); bool nowPlayingEnabled = config.now_playing.get().enabled; std::string nowPlaying = nowPlayingEnabled ? GetNowPlaying() : ""; - const std::string& name = config.general.get().name.get(); // Icon constants (using Nerd Font v3) - constexpr const char* calendarIcon = "  "; - constexpr const char* memoryIcon = "  "; - constexpr const char* osIcon = "  "; - constexpr const char* weatherIcon = " 󰖐 "; - constexpr const char* musicIcon = "  "; - const auto labelColor = Color::Yellow; - const auto valueColor = Color::White; - const auto borderColor = Color::GrayLight; - const auto iconColor = Color::RGB(100, 200, 255); // Bright cyan + constexpr const char* calendarIcon = "  "; + constexpr const char* memoryIcon = "  "; + constexpr const char* osIcon = "  "; + constexpr const char* weatherIcon = " 󰖐 "; + constexpr const char* musicIcon = "  "; + const Color::Palette16 labelColor = Color::Yellow; + const Color::Palette16 valueColor = Color::White; + const Color::Palette16 borderColor = Color::GrayLight; + const Color iconColor = Color::RGB(100, 200, 255); // Bright cyan Elements content; content.push_back(text("  Hello " + name + "! ") | bold | color(Color::Cyan)); @@ -122,12 +123,12 @@ namespace { } // Now Playing row - if (nowPlayingEnabled) { + if (nowPlayingEnabled && !nowPlaying.empty()) { content.push_back(separator() | color(borderColor)); content.push_back(hbox({ text(musicIcon), text("Now Playing ") | color(labelColor), filler(), - text(!nowPlaying.empty() ? nowPlaying : "No song playing"), + text(nowPlaying), text(" ") | color(Color::Magenta) })); } @@ -141,15 +142,11 @@ namespace { } fn main() -> i32 { - INFO_LOG("productFamily: {}", GetProductFamily()); - WARN_LOG("productFamily: {}", GetProductFamily()); - ERROR_LOG("productFamily: {}", GetProductFamily()); - const Config& config = Config::getInstance(); - auto document = hbox({ SystemInfoBox(config), filler() }); + Element document = hbox({ SystemInfoBox(config), filler() }); - auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); + Screen screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); screen.Print(); diff --git a/src/util/macros.h b/src/util/macros.h index 8ab0d35..239079a 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -21,12 +21,12 @@ namespace log_colors { enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR }; template -fn LogImpl( +void LogImpl( LogLevel level, const std::source_location& loc, fmt::format_string fmt, Args&&... args -) -> void { +) { const time_t now = std::time(nullptr); const auto [color, levelStr] = [&] { switch (level) { @@ -42,55 +42,31 @@ fn LogImpl( }(); const std::string filename = std::filesystem::path(loc.file_name()).lexically_normal().string(); - const u32 line = loc.line(); const struct tm time = *std::localtime(&now); - // Timestamp section + // Timestamp and level fmt::print(fg(log_colors::timestamp), "[{:%H:%M:%S}] ", time); + fmt::print(fmt::emphasis::bold | fg(color), "{} ", levelStr); - // Level section - fmt::print(fmt::emphasis::bold | fg(color), "{}", levelStr); - - // Message section - fmt::print(" "); + // Message fmt::print(fmt, std::forward(args)...); - // File info section + // File info (debug builds only) #ifndef NDEBUG fmt::print(fg(log_colors::file_info), "\n{:>14} ", "╰──"); - const std::string fileInfo = fmt::format("{}:{}", filename.c_str(), line); - fmt::print(fmt::emphasis::italic | fg(log_colors::file_info), "{}", fileInfo); + fmt::print(fmt::emphasis::italic | fg(log_colors::file_info), "{}:{}", filename, loc.line()); #endif fmt::print("\n"); } -// Logging utility wrapper to replace macros -// Logging utility wrapper to replace macros -template -struct LogWrapper { - std::source_location m_loc; // Changed to m_loc - - constexpr LogWrapper(const std::source_location& loc = std::source_location::current()) - : m_loc(loc) {} // Initialize member with parameter - - template - void operator()(fmt::format_string fmt, Args&&... args) const { - LogImpl(level, m_loc, fmt, std::forward(args)...); // Use m_loc - } -}; - -// Debug logging is conditionally compiled +// Minimal macros to capture source_location at call site #ifdef NDEBUG -struct { - template - void operator()(fmt::format_string, Args&&...) const {} -} DEBUG_LOG; +#define DEBUG_LOG(...) (void)0 #else -constexpr LogWrapper DEBUG_LOG; +#define DEBUG_LOG(...) LogImpl(LogLevel::DEBUG, std::source_location::current(), __VA_ARGS__) #endif -// Define loggers for other levels -constexpr LogWrapper INFO_LOG; -constexpr LogWrapper WARN_LOG; -constexpr LogWrapper ERROR_LOG; +#define INFO_LOG(...) LogImpl(LogLevel::INFO, std::source_location::current(), __VA_ARGS__) +#define WARN_LOG(...) LogImpl(LogLevel::WARN, std::source_location::current(), __VA_ARGS__) +#define ERROR_LOG(...) LogImpl(LogLevel::ERROR, std::source_location::current(), __VA_ARGS__)