uhgmasdgh

This commit is contained in:
Mars 2025-01-28 20:58:20 -05:00
parent bd8c149945
commit 39a6a5cff0
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
2 changed files with 29 additions and 56 deletions

View file

@ -1,5 +1,6 @@
#include <ctime> #include <ctime>
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <fmt/color.h>
#include <fmt/core.h> #include <fmt/core.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <ftxui/dom/elements.hpp> #include <ftxui/dom/elements.hpp>
@ -59,7 +60,7 @@ namespace {
fn CreateColorCircles() -> Element { fn CreateColorCircles() -> Element {
Elements circles; Elements circles;
for (int i = 0; i < 16; ++i) { 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(" ")); circles.push_back(text(" "));
} }
return hbox(circles); return hbox(circles);
@ -67,13 +68,13 @@ namespace {
fn SystemInfoBox(const Config& config) -> Element { fn SystemInfoBox(const Config& config) -> Element {
// Fetch data // Fetch data
const std::string& name = config.general.get().name.get();
std::string date = GetDate(); std::string date = GetDate();
u64 memInfo = GetMemInfo(); u64 memInfo = GetMemInfo();
std::string osVersion = GetOSVersion(); std::string osVersion = GetOSVersion();
Weather weather = config.weather.get(); Weather weather = config.weather.get();
bool nowPlayingEnabled = config.now_playing.get().enabled; bool nowPlayingEnabled = config.now_playing.get().enabled;
std::string nowPlaying = nowPlayingEnabled ? GetNowPlaying() : ""; std::string nowPlaying = nowPlayingEnabled ? GetNowPlaying() : "";
const std::string& name = config.general.get().name.get();
// Icon constants (using Nerd Font v3) // Icon constants (using Nerd Font v3)
constexpr const char* calendarIcon = ""; constexpr const char* calendarIcon = "";
@ -81,10 +82,10 @@ namespace {
constexpr const char* osIcon = ""; constexpr const char* osIcon = "";
constexpr const char* weatherIcon = " 󰖐 "; constexpr const char* weatherIcon = " 󰖐 ";
constexpr const char* musicIcon = ""; constexpr const char* musicIcon = "";
const auto labelColor = Color::Yellow; const Color::Palette16 labelColor = Color::Yellow;
const auto valueColor = Color::White; const Color::Palette16 valueColor = Color::White;
const auto borderColor = Color::GrayLight; const Color::Palette16 borderColor = Color::GrayLight;
const auto iconColor = Color::RGB(100, 200, 255); // Bright cyan const Color iconColor = Color::RGB(100, 200, 255); // Bright cyan
Elements content; Elements content;
content.push_back(text("  Hello " + name + "! ") | bold | color(Color::Cyan)); content.push_back(text("  Hello " + name + "! ") | bold | color(Color::Cyan));
@ -122,12 +123,12 @@ namespace {
} }
// Now Playing row // Now Playing row
if (nowPlayingEnabled) { if (nowPlayingEnabled && !nowPlaying.empty()) {
content.push_back(separator() | color(borderColor)); content.push_back(separator() | color(borderColor));
content.push_back(hbox({ text(musicIcon), content.push_back(hbox({ text(musicIcon),
text("Now Playing ") | color(labelColor), text("Now Playing ") | color(labelColor),
filler(), filler(),
text(!nowPlaying.empty() ? nowPlaying : "No song playing"), text(nowPlaying),
text(" ") | color(Color::Magenta) })); text(" ") | color(Color::Magenta) }));
} }
@ -141,15 +142,11 @@ namespace {
} }
fn main() -> i32 { fn main() -> i32 {
INFO_LOG("productFamily: {}", GetProductFamily());
WARN_LOG("productFamily: {}", GetProductFamily());
ERROR_LOG("productFamily: {}", GetProductFamily());
const Config& config = Config::getInstance(); 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); Render(screen, document);
screen.Print(); screen.Print();

View file

@ -21,12 +21,12 @@ namespace log_colors {
enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR }; enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR };
template <typename... Args> template <typename... Args>
fn LogImpl( void LogImpl(
LogLevel level, LogLevel level,
const std::source_location& loc, const std::source_location& loc,
fmt::format_string<Args...> fmt, fmt::format_string<Args...> fmt,
Args&&... args Args&&... args
) -> void { ) {
const time_t now = std::time(nullptr); const time_t now = std::time(nullptr);
const auto [color, levelStr] = [&] { const auto [color, levelStr] = [&] {
switch (level) { switch (level) {
@ -42,55 +42,31 @@ fn LogImpl(
}(); }();
const std::string filename = std::filesystem::path(loc.file_name()).lexically_normal().string(); 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); const struct tm time = *std::localtime(&now);
// Timestamp section // Timestamp and level
fmt::print(fg(log_colors::timestamp), "[{:%H:%M:%S}] ", time); fmt::print(fg(log_colors::timestamp), "[{:%H:%M:%S}] ", time);
// Level section
fmt::print(fmt::emphasis::bold | fg(color), "{} ", levelStr); fmt::print(fmt::emphasis::bold | fg(color), "{} ", levelStr);
// Message section // Message
fmt::print(" ");
fmt::print(fmt, std::forward<Args>(args)...); fmt::print(fmt, std::forward<Args>(args)...);
// File info section // File info (debug builds only)
#ifndef NDEBUG #ifndef NDEBUG
fmt::print(fg(log_colors::file_info), "\n{:>14} ", "╰──"); 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), "{}:{}", filename, loc.line());
fmt::print(fmt::emphasis::italic | fg(log_colors::file_info), "{}", fileInfo);
#endif #endif
fmt::print("\n"); fmt::print("\n");
} }
// Logging utility wrapper to replace macros // Minimal macros to capture source_location at call site
// Logging utility wrapper to replace macros
template <LogLevel level>
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 <typename... Args>
void operator()(fmt::format_string<Args...> fmt, Args&&... args) const {
LogImpl(level, m_loc, fmt, std::forward<Args>(args)...); // Use m_loc
}
};
// Debug logging is conditionally compiled
#ifdef NDEBUG #ifdef NDEBUG
struct { #define DEBUG_LOG(...) (void)0
template <typename... Args>
void operator()(fmt::format_string<Args...>, Args&&...) const {}
} DEBUG_LOG;
#else #else
constexpr LogWrapper<LogLevel::DEBUG> DEBUG_LOG; #define DEBUG_LOG(...) LogImpl(LogLevel::DEBUG, std::source_location::current(), __VA_ARGS__)
#endif #endif
// Define loggers for other levels #define INFO_LOG(...) LogImpl(LogLevel::INFO, std::source_location::current(), __VA_ARGS__)
constexpr LogWrapper<LogLevel::INFO> INFO_LOG; #define WARN_LOG(...) LogImpl(LogLevel::WARN, std::source_location::current(), __VA_ARGS__)
constexpr LogWrapper<LogLevel::WARN> WARN_LOG; #define ERROR_LOG(...) LogImpl(LogLevel::ERROR, std::source_location::current(), __VA_ARGS__)
constexpr LogWrapper<LogLevel::ERROR> ERROR_LOG;