I’m stuck on Stage #(QP2).
I’ve previously read all my commands as one line with getline().
I now use getchar(), but pressing the Tab-Key still does not lead to any direct result. It leads to a result, but I first need to tap enter(\n) after pressing it.
Here is the relevant function in my C++ code:
void CommandReader::readCharacterByCharacter(std::string ¤tInput, CommandManager &manager) {
char c;
while (true) {
c = static_cast<char>(getchar());
if (c == '\n') {
return; // Input line completed
} else if (c == '\t') {
// Autocompletion for Tab Key
std::vector<std::string> * suggestions = manager.getAllNamesWithPrefix(currentInput);
if (suggestions && suggestions->size() == 1) {
currentInput = suggestions->front();
std::cout << "\r" << currentInput << std::flush;
}
delete suggestions;
} else {
currentInput += c;
}
}
}
Here is a link to my GitHub Repo.