mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-12-22 13:29:48 +01:00
misc: move to std::print
This commit is contained in:
parent
ee37e41723
commit
0dc6f2a823
2 changed files with 22 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
enum eLogLevel {
|
enum eLogLevel {
|
||||||
TRACE = 0,
|
TRACE = 0,
|
||||||
|
@ -24,6 +24,17 @@ enum eLogLevel {
|
||||||
#define ASSERT(expr) RASSERT(expr, "?")
|
#define ASSERT(expr) RASSERT(expr, "?")
|
||||||
|
|
||||||
namespace Debug {
|
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 quiet = false;
|
||||||
inline bool verbose = false;
|
inline bool verbose = false;
|
||||||
|
|
||||||
|
@ -37,21 +48,7 @@ namespace Debug {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (level != NONE) {
|
if (level != NONE) {
|
||||||
std::cout << '[';
|
std::println("[{}] {}", logLevelString(level), std::vformat(fmt, std::make_format_args(args...)));
|
||||||
|
|
||||||
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::cout << std::vformat(fmt, std::make_format_args(args...)) << std::endl;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
18
src/main.cpp
18
src/main.cpp
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
#include "config/ConfigManager.hpp"
|
#include "config/ConfigManager.hpp"
|
||||||
#include "core/hyprlock.hpp"
|
#include "core/hyprlock.hpp"
|
||||||
#include "src/helpers/Log.hpp"
|
#include "helpers/Log.hpp"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
std::cout << "Usage: hyprlock [options]\n\n"
|
std::println("Usage: hyprlock [options]\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -v, --verbose - Enable verbose logging\n"
|
" -v, --verbose - Enable verbose logging\n"
|
||||||
" -q, --quiet - Disable 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"
|
" --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"
|
" --no-fade-in - Disable the fade-in animation when the lock screen appears\n"
|
||||||
" -V, --version - Show version information\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) {
|
std::optional<std::string> parseArg(const std::vector<std::string>& args, const std::string& flag, std::size_t& i) {
|
||||||
if (i + 1 < args.size()) {
|
if (i + 1 < args.size()) {
|
||||||
return args[++i];
|
return args[++i];
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Error: Missing value for " << flag << " option.\n";
|
std::println("Error: Missing value for {} option.", flag);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
if (arg == "--version" || arg == "-V") {
|
if (arg == "--version" || arg == "-V") {
|
||||||
constexpr bool ISTAGGEDRELEASE = std::string_view(HYPRLOCK_COMMIT) == HYPRLOCK_VERSION_COMMIT;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
noFadeIn = true;
|
noFadeIn = true;
|
||||||
|
|
||||||
else {
|
else {
|
||||||
std::cerr << "Unknown option: " << arg << "\n";
|
std::println(stderr, "Unknown option: {}", arg);
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue