diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command.cpp | 4 | ||||
-rw-r--r-- | src/misc.cpp | 32 | ||||
-rw-r--r-- | src/users.cpp | 1 |
3 files changed, 29 insertions, 8 deletions
diff --git a/src/command.cpp b/src/command.cpp index f307e8aa4..86d96a02e 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -198,9 +198,9 @@ const Anope::string Command::GetDesc(CommandSource &) const return this->desc; } -void Command::OnServHelp(CommandSource &source) +void Command::OnServHelp(CommandSource &source, HelpWrapper &help) { - source.Reply(" %-14s %s", source.command.c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str())); + help.AddEntry(source.command, this->GetDesc(source)); } bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; } diff --git a/src/misc.cpp b/src/misc.cpp index 40fac7db7..7b2759f90 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -264,8 +264,33 @@ void InfoFormatter::AddOption(const Anope::string &opt) *optstr += Language::Translate(nc, opt.c_str()); } -TextSplitter::TextSplitter(const Anope::string &t) - : text(t) + +void HelpWrapper::AddEntry(const Anope::string &name, const Anope::string &desc) +{ + entries.emplace_back(name, desc); + if (name.length() > longest) + longest = name.length(); +} + +void HelpWrapper::SendTo(CommandSource &source) +{ + const auto max_length = Config->GetBlock("options").Get<size_t>("linelength", "100") - longest - 8; + for (const auto &[entry_name, entry_desc] : entries) + { + TextSplitter splitter(Language::Translate(source.nc, entry_desc.c_str()), max_length); + + Anope::string line; + if (splitter.GetLine(line)) + source.Reply(" %-*s %s", (int)longest, entry_name.c_str(), line.c_str()); + + while (splitter.GetLine(line)) + source.Reply(" %-*s %s", (int)longest, "", line.c_str()); + } +}; + +TextSplitter::TextSplitter(const Anope::string &t, size_t ml) + : max_length(ml ? ml : Config->GetBlock("options").Get<size_t>("linelength", "100")) + , text(t) { } @@ -280,9 +305,6 @@ bool TextSplitter::GetLine(Anope::string &out) for (const auto &fmt : formatting) out.append(fmt); - // The maximum length of a line. - const auto max_length = Config->GetBlock("options").Get<size_t>("linelength", "100"); - // The current printable length of the output. size_t current_length = 0; diff --git a/src/users.cpp b/src/users.cpp index 33e840160..c252e51d7 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -21,7 +21,6 @@ #include "opertype.h" #include "language.h" #include "sockets.h" -#include "textproc.h" #include "uplink.h" user_map UserListByNick, UserListByUID; |