27#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
30#include <readline/readline.h>
31#include <readline/history.h>
43#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
44namespace Trinity::Impl::Readline
46 static std::vector<std::string> vec;
47 char* cli_unpack_vector(
char const*,
int state)
53 return strdup(vec[i++].c_str());
58 char** cli_completion(
char const* text,
int ,
int )
60 ::rl_attempted_completion_over = 1;
62 return ::rl_completion_matches(text, &cli_unpack_vector);
76#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
101 FD_SET(STDIN_FILENO, &fds);
102 select(STDIN_FILENO+1, &fds,
nullptr,
nullptr, &tv);
103 return FD_ISSET(STDIN_FILENO, &fds);
110#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
115 ::rl_attempted_completion_function = &Trinity::Impl::Readline::cli_completion;
117 static char BLANK =
'\0';
118 ::rl_completer_word_break_characters = &BLANK;
120 ::rl_event_hook = &Trinity::Impl::Readline::cli_hook_func;
123 if (
sConfigMgr->GetBoolDefault(
"BeepAtStart",
true))
126#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
127 if (
sConfigMgr->GetBoolDefault(
"FlashAtStart",
true))
130 fInfo.cbSize =
sizeof(FLASHWINFO);
131 fInfo.dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG;
132 fInfo.hwnd = GetConsoleWindow();
135 FlashWindowEx(&fInfo);
145#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
150 ::rl_bind_key(
'\t', ::rl_complete);
151 if (command_str !=
nullptr)
153 command = command_str;
158 if (!command.empty())
161 if (nextLineIndex && *nextLineIndex == 0)
163#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
171#if TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
172 add_history(command.c_str());
175 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.