aboutsummaryrefslogtreecommitdiff
path: root/src/server/worldserver/CommandLine
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-09-20 02:50:38 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-27 20:08:41 +0100
commit3fd2eb126cbed36292fa5defc024c2b93e8d8671 (patch)
tree6068f6e874d7552fcf00a92ca75a85381323a038 /src/server/worldserver/CommandLine
parent7a2c3af98831364988db25dd1bdd8ca10464c641 (diff)
[3.3.5] ChatCommands, the other half: chat command resolution refactor (PR #25463)
(cherry picked from commit 1eca51b417678b9a48b28552925d5694105f82bb)
Diffstat (limited to 'src/server/worldserver/CommandLine')
-rw-r--r--src/server/worldserver/CommandLine/CliRunnable.cpp70
1 files changed, 27 insertions, 43 deletions
diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp
index 5263d3ba3b6..a46d39478fe 100644
--- a/src/server/worldserver/CommandLine/CliRunnable.cpp
+++ b/src/server/worldserver/CommandLine/CliRunnable.cpp
@@ -39,54 +39,34 @@ static inline void PrintCliPrefix()
}
#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
-char* command_finder(char const* text, int state)
+namespace Trinity::Impl::Readline
{
- static size_t idx, len;
- char const* ret;
- std::vector<ChatCommand> const& cmd = ChatHandler::getCommandTable();
-
- if (!state)
+ static std::vector<std::string> vec;
+ char* cli_unpack_vector(char const*, int state)
{
- idx = 0;
- len = strlen(text);
+ static size_t i=0;
+ if (!state)
+ i = 0;
+ if (i < vec.size())
+ return strdup(vec[i++].c_str());
+ else
+ return nullptr;
}
- while (idx < cmd.size())
+ char** cli_completion(char const* text, int /*start*/, int /*end*/)
{
- ret = cmd[idx].Name;
- if (!cmd[idx].AllowConsole)
- {
- ++idx;
- continue;
- }
-
- ++idx;
- //printf("Checking %s \n", cmd[idx].Name);
- if (strncmp(ret, text, len) == 0)
- return strdup(ret);
+ ::rl_attempted_completion_over = 1;
+ vec = Trinity::ChatCommands::GetAutoCompletionsFor(CliHandler(nullptr,nullptr), text);
+ return ::rl_completion_matches(text, &cli_unpack_vector);
}
- return nullptr;
-}
-
-char** cli_completion(char const* text, int start, int /*end*/)
-{
- char** matches = nullptr;
-
- if (start)
- rl_bind_key('\t', rl_abort);
- else
- matches = rl_completion_matches((char*)text, &command_finder);
- return matches;
-}
-
-int cli_hook_func()
-{
- if (World::IsStopped())
- rl_done = 1;
- return 0;
+ int cli_hook_func()
+ {
+ if (World::IsStopped())
+ ::rl_done = 1;
+ return 0;
+ }
}
-
#endif
void utf8print(void* /*arg*/, std::string_view str)
@@ -134,8 +114,12 @@ void CliThread()
// later it will be printed after command queue updates
PrintCliPrefix();
#else
- rl_attempted_completion_function = cli_completion;
- rl_event_hook = cli_hook_func;
+ ::rl_attempted_completion_function = &Trinity::Impl::Readline::cli_completion;
+ {
+ static char BLANK = '\0';
+ ::rl_completer_word_break_characters = &BLANK;
+ }
+ ::rl_event_hook = &Trinity::Impl::Readline::cli_hook_func;
#endif
if (sConfigMgr->GetBoolDefault("BeepAtStart", true))
@@ -160,7 +144,7 @@ void CliThread()
}
#else
char* command_str = readline(CLI_PREFIX);
- rl_bind_key('\t', rl_complete);
+ ::rl_bind_key('\t', ::rl_complete);
if (command_str != nullptr)
{
command = command_str;