Skip to content

Commit 407ac75

Browse files
committed
args: add --debug
this way I can debug release builds easily
1 parent f2ec92d commit 407ac75

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

include/util.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// clang-format off
4343
// Get string literal length
4444
constexpr std::size_t operator""_len(const char*, std::size_t ln) noexcept
45-
{
45+
{
4646
return ln;
4747
}
4848

@@ -318,13 +318,18 @@ void die(const std::string_view fmt, Args&&... args) noexcept
318318
std::exit(1);
319319
}
320320

321+
#if DEBUG
322+
inline bool debug_print = true;
323+
#else
324+
inline bool debug_print = false;
325+
#endif
326+
321327
template <typename... Args>
322328
void debug(const std::string_view fmt, Args&&... args) noexcept
323329
{
324-
#if DEBUG
325-
fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::hot_pink))), "[DEBUG]:\033[0m {}\n",
326-
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
327-
#endif
330+
if (debug_print)
331+
fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::hot_pink))), "[DEBUG]:\033[0m {}\n",
332+
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
328333
}
329334

330335
template <typename... Args>

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
553553

554554
{"list-logos", no_argument, 0, "list-logos"_fnv1a16},
555555
{"sep-reset-after", optional_argument, 0, "sep-reset-after"_fnv1a16},
556+
{"debug", optional_argument, 0, "debug"_fnv1a16},
556557
{"wrap-lines", optional_argument, 0, "wrap-lines"_fnv1a16},
557558
{"gen-config", optional_argument, 0, "gen-config"_fnv1a16},
558559
{"sep-reset", required_argument, 0, "sep-reset"_fnv1a16},
@@ -629,6 +630,13 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
629630
case "loop-ms"_fnv1a16:
630631
config.loop_ms = std::stoul(optarg); break;
631632

633+
case "debug"_fnv1a16:
634+
if (OPTIONAL_ARGUMENT_IS_PRESENT)
635+
debug_print = str_to_bool(optarg);
636+
else
637+
debug_print = true;
638+
break;
639+
632640
case "bg-image"_fnv1a16:
633641
config.overrides["gui.bg-image"] = {.value_type = STR, .string_value = optarg}; break;
634642

0 commit comments

Comments
 (0)