misc: move to std::print

This commit is contained in:
Maximilian Seidler 2024-12-19 19:56:56 +01:00
parent ee37e41723
commit 0dc6f2a823
2 changed files with 22 additions and 25 deletions

View file

@ -1,7 +1,7 @@
#pragma once
#include <format>
#include <iostream>
#include <string>
#include <print>
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;
}
};

View file

@ -1,13 +1,13 @@
#include "config/ConfigManager.hpp"
#include "core/hyprlock.hpp"
#include "src/helpers/Log.hpp"
#include "helpers/Log.hpp"
#include <cstddef>
#include <iostream>
#include <string_view>
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 +17,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<std::string> parseArg(const std::vector<std::string>& 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("Error: Missing value for {} option.", flag);
return std::nullopt;
}
}
@ -48,11 +48,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 +84,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;
}