uhgmasdgh
This commit is contained in:
parent
bd8c149945
commit
39a6a5cff0
25
src/main.cpp
25
src/main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include <ctime>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
|
@ -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,13 +68,13 @@ 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 = " ";
|
||||
|
@ -81,10 +82,10 @@ namespace {
|
|||
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
|
||||
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();
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ namespace log_colors {
|
|||
enum class LogLevel : u8 { DEBUG, INFO, WARN, ERROR };
|
||||
|
||||
template <typename... Args>
|
||||
fn LogImpl(
|
||||
void LogImpl(
|
||||
LogLevel level,
|
||||
const std::source_location& loc,
|
||||
fmt::format_string<Args...> 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);
|
||||
|
||||
// Level section
|
||||
fmt::print(fmt::emphasis::bold | fg(color), "{} ", levelStr);
|
||||
|
||||
// Message section
|
||||
fmt::print(" ");
|
||||
// Message
|
||||
fmt::print(fmt, std::forward<Args>(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 <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
|
||||
// Minimal macros to capture source_location at call site
|
||||
#ifdef NDEBUG
|
||||
struct {
|
||||
template <typename... Args>
|
||||
void operator()(fmt::format_string<Args...>, Args&&...) const {}
|
||||
} DEBUG_LOG;
|
||||
#define DEBUG_LOG(...) (void)0
|
||||
#else
|
||||
constexpr LogWrapper<LogLevel::DEBUG> DEBUG_LOG;
|
||||
#define DEBUG_LOG(...) LogImpl(LogLevel::DEBUG, std::source_location::current(), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
// Define loggers for other levels
|
||||
constexpr LogWrapper<LogLevel::INFO> INFO_LOG;
|
||||
constexpr LogWrapper<LogLevel::WARN> WARN_LOG;
|
||||
constexpr LogWrapper<LogLevel::ERROR> 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__)
|
||||
|
|
Loading…
Reference in a new issue