|
@@ -27,6 +27,8 @@ Console::Console() {
|
27
|
27
|
mInputBuffer[INPUT_BUFFER_SIZE] = '\0';
|
28
|
28
|
mInputBufferPointer = 0;
|
29
|
29
|
mPartialInput = NULL;
|
|
30
|
+ mHistoryPointer = 0;
|
|
31
|
+ mUnfinishedInput = NULL;
|
30
|
32
|
}
|
31
|
33
|
|
32
|
34
|
Console::~Console() {
|
|
@@ -36,12 +38,22 @@ Console::~Console() {
|
36
|
38
|
if (mPartialInput)
|
37
|
39
|
delete [] mPartialInput;
|
38
|
40
|
|
|
41
|
+ if (mUnfinishedInput)
|
|
42
|
+ delete [] mUnfinishedInput;
|
|
43
|
+
|
39
|
44
|
while (mHistory.size() > 0) {
|
40
|
45
|
char *tmp = mHistory.back();
|
41
|
46
|
if (tmp != NULL)
|
42
|
47
|
delete [] tmp;
|
43
|
48
|
mHistory.pop_back();
|
44
|
49
|
}
|
|
50
|
+
|
|
51
|
+ while (mCommandHistory.size() > 0) {
|
|
52
|
+ char *tmp = mCommandHistory.back();
|
|
53
|
+ if (tmp != NULL)
|
|
54
|
+ delete [] tmp;
|
|
55
|
+ mCommandHistory.pop_back();
|
|
56
|
+ }
|
45
|
57
|
}
|
46
|
58
|
|
47
|
59
|
void Console::setVisible(bool visible) {
|
|
@@ -121,6 +133,7 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
|
121
|
133
|
// Execute entered command
|
122
|
134
|
if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
|
123
|
135
|
mHistory.push_back(bufferString("> %s", mInputBuffer));
|
|
136
|
+ mCommandHistory.push_back(bufferString("%s", mInputBuffer));
|
124
|
137
|
gOpenRaider->command(mInputBuffer);
|
125
|
138
|
}
|
126
|
139
|
|
|
@@ -131,6 +144,8 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
|
131
|
144
|
delete [] mPartialInput;
|
132
|
145
|
mPartialInput = NULL;
|
133
|
146
|
}
|
|
147
|
+
|
|
148
|
+ mHistoryPointer = 0;
|
134
|
149
|
}
|
135
|
150
|
|
136
|
151
|
//! \fixme only deleting the last byte is not valid for non-ASCII UTF-8 strings
|
|
@@ -140,6 +155,46 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
|
140
|
155
|
mInputBuffer[mInputBufferPointer] = '\0';
|
141
|
156
|
}
|
142
|
157
|
}
|
|
158
|
+
|
|
159
|
+ if (pressed && ((key == up) || (key == down))) {
|
|
160
|
+ moveInHistory(key == up);
|
|
161
|
+ }
|
|
162
|
+}
|
|
163
|
+
|
|
164
|
+void Console::moveInHistory(bool up) {
|
|
165
|
+ if (mCommandHistory.size() == 0)
|
|
166
|
+ return;
|
|
167
|
+
|
|
168
|
+ if (up) {
|
|
169
|
+ if (mHistoryPointer < mCommandHistory.size()) {
|
|
170
|
+ mHistoryPointer++;
|
|
171
|
+ if (mHistoryPointer == 1) {
|
|
172
|
+ mUnfinishedInput = bufferString("%s", mInputBuffer);
|
|
173
|
+ }
|
|
174
|
+ } else {
|
|
175
|
+ return;
|
|
176
|
+ }
|
|
177
|
+ } else {
|
|
178
|
+ if (mHistoryPointer > 0)
|
|
179
|
+ mHistoryPointer--;
|
|
180
|
+ else
|
|
181
|
+ return;
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ if ((mHistoryPointer > 0) && (mHistoryPointer <= mCommandHistory.size())) {
|
|
185
|
+ strcpy(mInputBuffer, mCommandHistory[mCommandHistory.size() - mHistoryPointer]);
|
|
186
|
+ mInputBufferPointer = strlen(mInputBuffer);
|
|
187
|
+ } else {
|
|
188
|
+ if (mUnfinishedInput != NULL) {
|
|
189
|
+ strcpy(mInputBuffer, mUnfinishedInput);
|
|
190
|
+ mInputBufferPointer = strlen(mInputBuffer);
|
|
191
|
+ delete [] mUnfinishedInput;
|
|
192
|
+ mUnfinishedInput = NULL;
|
|
193
|
+ } else {
|
|
194
|
+ mInputBuffer[0] = '\0';
|
|
195
|
+ mInputBufferPointer = 0;
|
|
196
|
+ }
|
|
197
|
+ }
|
143
|
198
|
}
|
144
|
199
|
|
145
|
200
|
void Console::handleText(char *text, bool notFinished) {
|