32#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
36#include <readline/readline.h>
37#include <readline/history.h>
49#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
50namespace Trinity::Impl::Readline
52 static std::vector<std::string> vec;
53 char* cli_unpack_vector(
char const*,
int state)
59 return strdup(vec[i++].c_str());
64 char** cli_completion(
char const* text,
int ,
int )
66 ::rl_attempted_completion_over = 1;
68 return ::rl_completion_matches(text, &cli_unpack_vector);
82#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
107 FD_SET(STDIN_FILENO, &fds);
108 select(STDIN_FILENO+1, &fds,
nullptr,
nullptr, &tv);
109 return FD_ISSET(STDIN_FILENO, &fds);
116#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
121 ::rl_attempted_completion_function = &Trinity::Impl::Readline::cli_completion;
123 static char BLANK =
'\0';
124 ::rl_completer_word_break_characters = &BLANK;
126 ::rl_event_hook = &Trinity::Impl::Readline::cli_hook_func;
129 if (
sConfigMgr->GetBoolDefault(
"BeepAtStart",
true))
132#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
133 if (
sConfigMgr->GetBoolDefault(
"FlashAtStart",
true))
136 fInfo.cbSize =
sizeof(FLASHWINFO);
137 fInfo.dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG;
138 fInfo.hwnd = GetConsoleWindow();
141 FlashWindowEx(&fInfo);
151#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
156 ::rl_bind_key(
'\t', ::rl_complete);
157 if (command_str !=
nullptr)
159 command = command_str;
164 if (!command.empty())
167 if (nextLineIndex && *nextLineIndex == 0)
169#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
177#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
178 add_history(command.c_str());
181 else if (feof(stdin))
#define STRING_VIEW_FMT_ARG(str)
std::optional< T > Optional
Optional helper class to wrap optional values within.
bool WriteWinConsole(std::string_view str, bool error)
TC_COMMON_API Optional< std::size_t > RemoveCRLF(std::string &str)
bool ReadWinConsole(std::string &str, size_t size)
static void StopNow(uint8 exitcode)
void CliThread()
Thread start
static void PrintCliPrefix()
static constexpr char CLI_PREFIX[]
void utf8print(void *, std::string_view str)
void commandFinished(void *, bool)
TC_GAME_API std::vector< std::string > GetAutoCompletionsFor(ChatHandler const &handler, std::string_view cmd)
Storage class for commands issued for delayed execution.