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>
This commit is contained in:
Max Drosdo.www
2020-06-17 23:14:27 +03:00
committed by GitHub
parent 8fef9aaf75
commit 1e9c84a3ea

View File

@@ -32,7 +32,16 @@
#include <readline/readline.h>
#include <readline/history.h>
#include "Chat.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;
@@ -102,7 +111,7 @@ void utf8print(void* /*arg*/, char const* str)
void commandFinished(void*, bool /*success*/)
{
printf("TC> ");
PrintCliPrefix();
fflush(stdout);
}
@@ -124,9 +133,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
@@ -134,10 +145,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())
{
@@ -151,12 +158,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)
{
@@ -173,7 +180,7 @@ void CliThread()
if (nextLineIndex == 0)
{
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
printf("TC>");
PrintCliPrefix();
#endif
continue;
}