Cube  Diff

Differences From Artifact [979d6ed7fb]:

To Artifact [635cf832c8]:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
vector<cline> conlines;

const int ndraw = 5;
const int WORDWRAP = 80;
int conskip = 0;

bool saycommandon = false;
string commandbuf;

void
setconskip(int n)
{
	conskip += n;
	if (conskip < 0)
		conskip = 0;







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
vector<cline> conlines;

const int ndraw = 5;
const int WORDWRAP = 80;
int conskip = 0;

bool saycommandon = false;
static OFMutableString *commandbuf;

void
setconskip(int n)
{
	conskip += n;
	if (conskip < 0)
		conskip = 0;
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139

140
141
142

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

158
159

160
161
162
163
164
165
166
167
168
169
170
	}

	conoutf(@"unknown key \"%@\"", key);
}
COMMANDN(bind, bindkey, ARG_2STR)

void
saycommand(char *init) // turns input to the command line on or off
{
	saycommandon = (init != NULL);
	if (saycommandon)
		SDL_StartTextInput();
	else
		SDL_StopTextInput();

	if (!editmode)
		Cube.sharedInstance.repeatsKeys = saycommandon;

	if (!init)
		init = "";
	strcpy_s(commandbuf, init);

}
COMMAND(saycommand, ARG_VARI)

void
mapmsg(OFString *s)
{
	@autoreleasepool {
		strn0cpy(hdr.maptitle, s.UTF8String, 128);
	}
}
COMMAND(mapmsg, ARG_1STR)

void
pasteconsole()
{

	char *cb = SDL_GetClipboardText();
	strcat_s(commandbuf, cb);

}

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

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

	if (!rec && n >= 0 && n < vhistory.count) {







|






>


>


|
>















>
|
<
>



|







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
	}

	conoutf(@"unknown key \"%@\"", key);
}
COMMANDN(bind, bindkey, ARG_2STR)

void
saycommand(const char *init) // turns input to the command line on or off
{
	saycommandon = (init != NULL);
	if (saycommandon)
		SDL_StartTextInput();
	else
		SDL_StopTextInput();

	if (!editmode)
		Cube.sharedInstance.repeatsKeys = saycommandon;

	if (!init)
		init = "";

	commandbuf = [[OFMutableString alloc] initWithUTF8String:init];
}
COMMAND(saycommand, ARG_VARI)

void
mapmsg(OFString *s)
{
	@autoreleasepool {
		strn0cpy(hdr.maptitle, s.UTF8String, 128);
	}
}
COMMAND(mapmsg, ARG_1STR)

void
pasteconsole()
{
	@autoreleasepool {
		[commandbuf appendString:@(SDL_GetClipboardText())];

	}
}

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

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

	if (!rec && n >= 0 && n < vhistory.count) {
185
186
187
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
254


255
256
257



258
259
260
261
262
263
264
265
266
267
268
		if (isdown) {
			switch (code) {
			case SDLK_RETURN:
				break;

			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) {
					@autoreleasepool {
						strcpy_s(commandbuf,
						    vhistory[--histpos]
						        .UTF8String);
					}
				}
				break;

			case SDLK_DOWN:
				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 == nil)
							vhistory =
							    [[OFMutableArray
							        alloc] init];

						if (vhistory.count == 0 ||
						    ![vhistory.lastObject
						        isEqual:cmdbuf]) {
							// cap this?
							[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)) {







|
>
|
|





|
<
|
|
<
<
<



|
<
|
|
<
<
<











<
>



|
<
|
<



|

<
<
<







|


|
>
>



>
>
>
|
|
|
|







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
254
255
256
257
258
259
260
261
262
263
264
265
		if (isdown) {
			switch (code) {
			case SDLK_RETURN:
				break;

			case SDLK_BACKSPACE:
			case SDLK_LEFT: {
				[commandbuf
				    deleteCharactersInRange:
				        OFMakeRange(commandbuf.length - 1, 1)];

				resetcomplete();
				break;
			}

			case SDLK_UP:
				if (histpos)

					commandbuf =
					    [vhistory[--histpos] mutableCopy];



				break;

			case SDLK_DOWN:
				if (histpos < vhistory.count)

					commandbuf =
					    [vhistory[histpos++] mutableCopy];



				break;

			case SDLK_TAB:
				complete(commandbuf);
				break;

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

				}

			default:
				resetcomplete();
				if (cooked)

					[commandbuf appendFormat:@"%c", cooked];

			}
		} else {
			if (code == SDLK_RETURN) {
				if (commandbuf.length > 0) {
					@autoreleasepool {



						if (vhistory == nil)
							vhistory =
							    [[OFMutableArray
							        alloc] init];

						if (vhistory.count == 0 ||
						    ![vhistory.lastObject
						        isEqual:commandbuf]) {
							// cap this?
							[vhistory
							    addObject:
							        [commandbuf
							            copy]];
						}
					}
					histpos = vhistory.count;
					if ([commandbuf hasPrefix:@"/"]) {
						std::unique_ptr<char> copy(
						    strdup(
						        commandbuf.UTF8String));
						execute(copy.get(), true);
					} else
						toserver(commandbuf.UTF8String);
				}
				saycommand(NULL);
			} else if (code == SDLK_ESCAPE) {
				saycommand(NULL);
			}
		}
	} else if (!menukey(code, isdown)) {
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
				execute(temp, isdown);
				return;
			}
		}
	}
}

char *
getcurcommand()
{
	return saycommandon ? commandbuf : NULL;
}

void
writebinds(OFStream *stream)
{
	for (KeyMapping *mapping in keyMappings)
		if (mapping.action.length > 0)
			[stream writeFormat:@"bind \"%@\" [%@]\n", mapping.name,
			        mapping.action];
}







|













274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
				execute(temp, isdown);
				return;
			}
		}
	}
}

OFString *
getcurcommand()
{
	return saycommandon ? commandbuf : NULL;
}

void
writebinds(OFStream *stream)
{
	for (KeyMapping *mapping in keyMappings)
		if (mapping.action.length > 0)
			[stream writeFormat:@"bind \"%@\" [%@]\n", mapping.name,
			        mapping.action];
}