Browse Source

Fixed console input

release/0.19
Jessica James 5 years ago
parent
commit
b9d976ef07
  1. 12
      src/Bot/src/Main.cpp

12
src/Bot/src/Main.cpp

@ -66,19 +66,17 @@ void onExit()
void inputLoop() void inputLoop()
{ {
char input[INPUT_BUFFER_SIZE]; std::string input;
size_t input_length;
while (ftell(stdin) != -1 || errno != EBADF) while (ftell(stdin) != -1 || errno != EBADF)
{ {
fgets(input, sizeof(input), stdin); std::getline(std::cin, input);
input_length = strcspn(input, "\r\n");
check_input_processing: check_input_processing:
std::lock_guard<std::mutex> guard(console_input.input_mutex); std::lock_guard<std::mutex> guard(console_input.input_mutex);
if (console_input.awaiting_processing == false) if (console_input.awaiting_processing == false)
{ {
console_input.input.set(input, input_length); console_input.input = input;
console_input.awaiting_processing = true; console_input.awaiting_processing = true;
} }
else // User input received before previous input was processed. else // User input received before previous input was processed.
@ -210,11 +208,11 @@ int main(int argc, const char **args)
if (console_input.awaiting_processing) if (console_input.awaiting_processing)
{ {
console_input.awaiting_processing = false; console_input.awaiting_processing = false;
command = console_input.input.getWord(0, WHITESPACE); command = Jupiter::ReferenceString::getWord(console_input.input, 0, WHITESPACE);
ConsoleCommand *cmd = getConsoleCommand(command); ConsoleCommand *cmd = getConsoleCommand(command);
if (cmd != nullptr) if (cmd != nullptr)
cmd->trigger(console_input.input.gotoWord(1, WHITESPACE)); cmd->trigger(Jupiter::ReferenceString::gotoWord(console_input.input, 1, WHITESPACE));
else else
printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr()); printf("Error: Command \"%.*s\" not found." ENDL, command.size(), command.ptr());
} }

Loading…
Cancel
Save