feat: Implement history in console

This commit is contained in:
Vsevolod Kremianskii 2021-01-09 03:33:13 +07:00
parent 3862725035
commit 0a623c7564
4 changed files with 15 additions and 0 deletions

View file

@ -247,10 +247,17 @@ bool Console::handleKeyUp(const SDL_KeyboardEvent &event) {
string text(_input.text());
if (!text.empty()) {
executeInputText();
_history.push(_input.text());
_input.clear();
}
return true;
}
case SDLK_UP:
if (!_history.empty()) {
_input.setText(_history.top());
_history.pop();
}
return true;
default:
return false;
}

View file

@ -19,6 +19,7 @@
#include <functional>
#include <memory>
#include <stack>
#include <string>
#include <queue>
#include <unordered_map>
@ -56,6 +57,7 @@ private:
std::deque<std::string> _output;
int _outputOffset { 0 };
std::unordered_map<std::string, CommandHandler> _commands;
std::stack<std::string> _history;
Console(const Console &) = delete;
Console &operator=(const Console &) = delete;

View file

@ -103,6 +103,10 @@ const string &TextInput::text() const {
return _text;
}
void TextInput::setText(string text) {
_text = move(text);
}
} // namespace gui
} // namespace reone

View file

@ -42,6 +42,8 @@ public:
const std::string &text() const;
void setText(std::string text);
private:
int _mask { 0 };
std::string _text;