Skip to content

Commit

Permalink
misc: move to std::print
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Dec 22, 2024
1 parent ee37e41 commit 14e53ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
29 changes: 13 additions & 16 deletions src/helpers/Log.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <format>
#include <iostream>
#include <string>
#include <print>

enum eLogLevel {
TRACE = 0,
Expand All @@ -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;

Expand All @@ -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;
}
};
19 changes: 9 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

#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"
Expand All @@ -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<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(stderr, "Error: Missing value for {} option.", flag);
return std::nullopt;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 14e53ac

Please sign in to comment.