Cube  Diff

Differences From Artifact [39120f3a5f]:

To Artifact [979d6ed7fb]:


155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170

171
172



173
174
175
176
177
178
179
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169

170
171

172
173
174
175
176
177
178
179
180
181







-
+







-
+

-
+
+
+







void
pasteconsole()
{
	char *cb = SDL_GetClipboardText();
	strcat_s(commandbuf, cb);
}

cvector vhistory;
static OFMutableArray<OFString *> *vhistory;
int histpos = 0;

void
history(int n)
{
	static bool rec = false;

	if (!rec && n >= 0 && n < vhistory.length()) {
	if (!rec && n >= 0 && n < vhistory.count) {
		rec = true;
		execute(vhistory[vhistory.length() - n - 1]);
		OFString *cmd = vhistory[vhistory.count - n - 1];
		std::unique_ptr<char> copy(strdup(cmd.UTF8String));
		execute(copy.get());
		rec = false;
	}
}
COMMAND(history, ARG_1INT)

void
keypress(int code, bool isdown, int cooked)
188
189
190
191
192
193
194
195
196


197
198
199
200







201
202
203
204
205
206







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226


227
228
229




230
231
232
233
234









235
236





237
238
239
240
241

242
243
244
245
246


247
248
249
250
251
252
253
190
191
192
193
194
195
196


197
198
199



200
201
202
203
204
205
206
207
208
209



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234


235
236
237
238
239
240
241
242
243





244
245
246
247
248
249
250
251
252


253
254
255
256
257
258
259
260
261

262
263
264
265


266
267
268
269
270
271
272
273
274







-
-
+
+

-
-
-
+
+
+
+
+
+
+



-
-
-
+
+
+
+
+
+
+


















-
-
+
+



+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+




-
+



-
-
+
+







			case SDLK_BACKSPACE:
			case SDLK_LEFT: {
				for (int i = 0; commandbuf[i]; i++)
					if (!commandbuf[i + 1])
						commandbuf[i] = 0;
				resetcomplete();
				break;
			};

			}

			case SDLK_UP:
				if (histpos)
					strcpy_s(
					    commandbuf, vhistory[--histpos]);
				if (histpos) {
					@autoreleasepool {
						strcpy_s(commandbuf,
						    vhistory[--histpos]
						        .UTF8String);
					}
				}
				break;

			case SDLK_DOWN:
				if (histpos < vhistory.length())
					strcpy_s(
					    commandbuf, vhistory[histpos++]);
				if (histpos < vhistory.count) {
					@autoreleasepool {
						strcpy_s(commandbuf,
						    vhistory[histpos++]
						        .UTF8String);
					}
				}
				break;

			case SDLK_TAB:
				complete(commandbuf);
				break;

			case SDLK_v:
				if (SDL_GetModState() &
				    (KMOD_LCTRL | KMOD_RCTRL)) {
					pasteconsole();
					return;
				};

			default:
				resetcomplete();
				if (cooked) {
					char add[] = {(char)cooked, 0};
					strcat_s(commandbuf, add);
				};
			};
				}
			}
		} else {
			if (code == SDLK_RETURN) {
				if (commandbuf[0]) {
					@autoreleasepool {
						OFString *cmdbuf =
						    @(commandbuf);

					if (vhistory.empty() ||
					    strcmp(
					        vhistory.last(), commandbuf)) {
						vhistory.add(newstring(
						    commandbuf)); // cap this?
						if (vhistory == nil)
							vhistory =
							    [[OFMutableArray
							        alloc] init];

						if (vhistory.count == 0 ||
						    ![vhistory.lastObject
						        isEqual:cmdbuf]) {
							// cap this?
					};
					histpos = vhistory.length();
							[vhistory
							    addObject:cmdbuf];
						}
					}
					histpos = vhistory.count;
					if (commandbuf[0] == '/')
						execute(commandbuf, true);
					else
						toserver(commandbuf);
				};
				}
				saycommand(NULL);
			} else if (code == SDLK_ESCAPE) {
				saycommand(NULL);
			};
		};
			}
		}
	} else if (!menukey(code, isdown)) {
		// keystrokes go to menu

		for (KeyMapping *mapping in keyMappings) {
			if (mapping.code == code) {
				// keystrokes go to game, lookup in keymap and
				// execute