From 14e53acbddc0b2c32fba673f534167a029f7d48a Mon Sep 17 00:00:00 2001 From: Maximilian Seidler Date: Thu, 19 Dec 2024 19:56:56 +0100 Subject: [PATCH] misc: move to std::print --- src/helpers/Log.hpp | 29 +++++++++++++---------------- src/main.cpp | 19 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/helpers/Log.hpp b/src/helpers/Log.hpp index 357f4f5..00770da 100644 --- a/src/helpers/Log.hpp +++ b/src/helpers/Log.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include #include +#include enum eLogLevel { TRACE = 0, @@ -24,6 +24,17 @@ enum eLogLevel { #define ASSERT(expr) RASSERT(expr, "?") namespace Debug { + constexpr const char* logLevelString(eLogLevel level) { + switch (level) { + case TRACE: return "TRACE"; break; + case INFO: return "INFO"; break; + case LOG: return "LOG"; break; + case WARN: return "WARN"; break; + case ERR: return "ERR"; break; + case CRIT: return "CRITICAL"; break; + default: return "??"; + } + } inline bool quiet = false; inline bool verbose = false; @@ -37,21 +48,7 @@ namespace Debug { return; if (level != NONE) { - std::cout << '['; - - switch (level) { - case TRACE: std::cout << "TRACE"; break; - case INFO: std::cout << "INFO"; break; - case LOG: std::cout << "LOG"; break; - case WARN: std::cout << "WARN"; break; - case ERR: std::cout << "ERR"; break; - case CRIT: std::cout << "CRITICAL"; break; - default: break; - } - - std::cout << "] "; + std::println("[{}] {}", logLevelString(level), std::vformat(fmt, std::make_format_args(args...))); } - - std::cout << std::vformat(fmt, std::make_format_args(args...)) << std::endl; } }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a4572ab..f80c480 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,12 @@ #include "config/ConfigManager.hpp" #include "core/hyprlock.hpp" -#include "src/helpers/Log.hpp" +#include "helpers/Log.hpp" #include -#include #include void help() { - std::cout << "Usage: hyprlock [options]\n\n" + std::println("Usage: hyprlock [options]\n\n" "Options:\n" " -v, --verbose - Enable verbose logging\n" " -q, --quiet - Disable logging\n" @@ -17,14 +16,14 @@ void help() { " --immediate-render - Do not wait for resources before drawing the background\n" " --no-fade-in - Disable the fade-in animation when the lock screen appears\n" " -V, --version - Show version information\n" - " -h, --help - Show this help message\n"; + " -h, --help - Show this help message"); } std::optional parseArg(const std::vector& args, const std::string& flag, std::size_t& i) { if (i + 1 < args.size()) { return args[++i]; } else { - std::cerr << "Error: Missing value for " << flag << " option.\n"; + std::println(stderr, "Error: Missing value for {} option.", flag); return std::nullopt; } } @@ -48,11 +47,11 @@ int main(int argc, char** argv, char** envp) { if (arg == "--version" || arg == "-V") { constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT; + if (ISTAGGEDRELEASE) + std::println("Hyprlock version v{}", HYPRLOCK_VERSION); + else + std::println("Hyprlock version v{} (commit {})", HYPRLOCK_VERSION, HYPRLOCK_VERSION_COMMIT); - std::cout << "Hyprlock version v" << HYPRLOCK_VERSION; - if (!ISTAGGEDRELEASE) - std::cout << " (commit " << HYPRLOCK_COMMIT << ")"; - std::cout << std::endl; return 0; } @@ -84,7 +83,7 @@ int main(int argc, char** argv, char** envp) { noFadeIn = true; else { - std::cerr << "Unknown option: " << arg << "\n"; + std::println(stderr, "Unknown option: {}", arg); help(); return 1; }