diff options
author | Max Drosdo.www <g1ran1q@gmail.com> | 2020-06-17 23:14:27 +0300 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-01-06 22:10:03 +0100 |
commit | 1b605eb5b06611733e985ac15f33bcf4fb7527a3 (patch) | |
tree | e6b254ed7d1708ce5d57ee6a8ef9ce13db23b268 | |
parent | ef8998f52b209233cd44c01c068a5327aacf66cd (diff) |
Worldserver/CLI: console printf fix (#24802)
* Remove extra cli printf call for non-Windows systems
* Codestyle changes
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
(cherry picked from commit 1e9c84a3ea0c3f255779eada0d804fab15e2e434)
-rw-r--r-- | src/server/worldserver/CommandLine/CliRunnable.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index b20aafef6a1..29981235cfb 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -37,7 +37,16 @@ #if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS #include <readline/readline.h> #include <readline/history.h> +#endif + +static constexpr char CLI_PREFIX[] = "TC> "; +static inline void PrintCliPrefix() +{ + printf("%s", CLI_PREFIX); +} + +#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS char* command_finder(char const* text, int state) { static size_t idx, len; @@ -107,7 +116,7 @@ void utf8print(void* /*arg*/, char const* str) void commandFinished(void*, bool /*success*/) { - printf("TC> "); + PrintCliPrefix(); fflush(stdout); } @@ -129,9 +138,11 @@ int kb_hit_return() /// %Thread start void CliThread() { - ///- Display the list of available CLI functions then beep - //TC_LOG_INFO("server.worldserver", ""); -#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS + // print this here the first time + // later it will be printed after command queue updates + PrintCliPrefix(); +#else rl_attempted_completion_function = cli_completion; rl_event_hook = cli_hook_func; #endif @@ -139,10 +150,6 @@ void CliThread() if (sConfigMgr->GetBoolDefault("BeepAtStart", true)) printf("\a"); // \a = Alert - // print this here the first time - // later it will be printed after command queue updates - printf("TC>"); - ///- As long as the World is running (no World::m_stopEvent), get the command line and handle it while (!World::IsStopped()) { @@ -156,12 +163,12 @@ void CliThread() { if (!WStrToUtf8(commandbuf, wcslen(commandbuf), command)) { - printf("TC>"); + PrintCliPrefix(); continue; } } #else - char* command_str = readline("TC>"); + char* command_str = readline(CLI_PREFIX); rl_bind_key('\t', rl_complete); if (command_str != nullptr) { @@ -178,7 +185,7 @@ void CliThread() if (nextLineIndex == 0) { #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS - printf("TC>"); + PrintCliPrefix(); #endif continue; } |