Debian Codegraph @

hyprtester/src/Log.hpp

raw
1 #pragma once
2 #include <string>
3 #include <format>
4 #include <print>
5 #include <utility>
6
7 // Stolen from hyprutils
8 namespace Colors {
9 constexpr const char* RED = "\x1b[31m";
10 constexpr const char* GREEN = "\x1b[32m";
11 constexpr const char* YELLOW = "\x1b[33m";
12 constexpr const char* BLUE = "\x1b[34m";
13 constexpr const char* MAGENTA = "\x1b[35m";
14 constexpr const char* CYAN = "\x1b[36m";
15 constexpr const char* RESET = "\x1b[0m";
16 };
17
18 namespace NLog {
19 template <typename... Args>
20 // NOLINTNEXTLINE
21 void log(std::format_string<Args...> fmt, Args&&... args) {
22 std::string logMsg = "";
23
24 logMsg += std::format(fmt, std::forward<Args>(args)...);
25
26 std::println("{}{}", logMsg, Colors::RESET);
27 std::fflush(stdout);
28 }
29
30 template <typename... Args>
31 // NOLINTNEXTLINE
32 void yellow(std::format_string<Args...> fmt, Args&&... args) {
33 auto msg = std::vformat(fmt.get(), std::make_format_args(args...));
34 log("{}{}", Colors::YELLOW, msg);
35 }
36
37 template <typename... Args>
38 // NOLINTNEXTLINE
39 void green(std::format_string<Args...> fmt, Args&&... args) {
40 auto msg = std::vformat(fmt.get(), std::make_format_args(args...));
41 log("{}{}", Colors::GREEN, msg);
42 }
43
44 template <typename... Args>
45 // NOLINTNEXTLINE
46 void red(std::format_string<Args...> fmt, Args&&... args) {
47 auto msg = std::vformat(fmt.get(), std::make_format_args(args...));
48 log("{}{}", Colors::RED, msg);
49 }
50 }