From e447713921ecf26760f0279cabd10e0095715659 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Wed, 15 Jan 2025 09:25:38 +1300 Subject: [PATCH] log_help: {add,push,pop}_content helpers --- kernel/log_help.cc | 17 +++++++---------- kernel/log_help.h | 12 ++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/kernel/log_help.cc b/kernel/log_help.cc index 137a75a5e..7c9b88f06 100644 --- a/kernel/log_help.cc +++ b/kernel/log_help.cc @@ -102,7 +102,7 @@ void PrettyHelp::usage(const string &usage, log("\n"); break; case LISTING: - _current_listing->add_content("usage", usage, location); + add_content("usage", usage, location); break; default: log_abort(); @@ -121,7 +121,7 @@ void PrettyHelp::option(const string &text, const string &description, log("\n"); break; case LISTING: - _current_listing->add_content("text", description, location); + add_content("text", description, location); break; default: log_abort(); @@ -139,7 +139,7 @@ void PrettyHelp::codeblock(const string &code, const string &language, log("%s\n", code.c_str()); break; case LISTING: - _current_listing->add_content("code", code, location); + add_content("code", code, location); break; default: log_abort(); @@ -156,7 +156,7 @@ void PrettyHelp::paragraph(const string &text, log("\n"); break; case LISTING: - _current_listing->add_content("text", text, location); + add_content("text", text, location); break; default: log_abort(); @@ -171,8 +171,7 @@ void PrettyHelp::open_optiongroup(const string &name, case LOG: break; case LISTING: - _current_listing->add_content("optiongroup", name, location); - _current_listing = _current_listing->content.back(); + push_content("optiongroup", name, location); break; default: log_abort(); @@ -189,8 +188,7 @@ void PrettyHelp::open_option(const string &text, log_pass_str(text, _current_indent); break; case LISTING: - _current_listing->add_content("option", text, location); - _current_listing = _current_listing->content.back(); + push_content("option", text, location); break; default: log_abort(); @@ -211,8 +209,7 @@ void PrettyHelp::close(int levels) for (int i=0; i= 0); - _current_listing = _current_listing->parent; - log_assert(_current_listing != nullptr); + pop_content(); } break; default: diff --git a/kernel/log_help.h b/kernel/log_help.h index dd06e88e5..e4ddc52d6 100644 --- a/kernel/log_help.h +++ b/kernel/log_help.h @@ -78,6 +78,18 @@ private: int _current_indent = 0; ContentListing _root_listing; ContentListing *_current_listing; + + void add_content(string type, string body, source_location location) { + _current_listing->add_content(type, body, location); + } + void push_content(string type, string body, source_location location) { + add_content(type, body, location); + _current_listing = _current_listing->content.back(); + } + void pop_content() { + _current_listing = _current_listing->parent; + log_assert(_current_listing != nullptr); + } public: PrettyHelp(Mode mode = LOG); ~PrettyHelp();