Cube  Diff

Differences From Artifact [c4ec2131b8]:

To Artifact [555c5a6eb3]:


1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1
2
3
4
5
6
7
8
9
10







11
12

















13
14
15
16
17
18
19






+



-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







// console.cpp: the console buffer, its display, and command line control

#include "cube.h"

#include <ctype.h>

#import "ConsoleLine.h"
#import "KeyMapping.h"
#import "OFString+Cube.h"

@interface ConsoleLine: OFObject
@property (readonly, copy) OFString *text;
@property (readonly) int outtime;

- (instancetype)initWithText:(OFString *)text outtime:(int)outtime;
@end

static OFMutableArray<ConsoleLine *> *conlines;

@implementation ConsoleLine
- (instancetype)initWithText:(OFString *)text outtime:(int)outtime
{
	self = [super init];

	_text = [text copy];
	_outtime = outtime;

	return self;
}

- (OFString *)description
{
	return _text;
}
@end

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

bool saycommandon = false;
static OFMutableString *commandbuf;

55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49


50
51
52
53
54
55
56
57
58







-
+










-
-
+
+







	OFMutableString *text;

	// constrain the buffer size
	if (conlines.count > 100) {
		text = [conlines.lastObject.text mutableCopy];
		[conlines removeLastObject];
	} else
		text = [[OFMutableString alloc] init];
		text = [OFMutableString string];

	if (highlight)
		// show line in a different colour, for chat etc.
		[text appendString:@"\f"];

	[text appendString:sf];

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

	[conlines insertObject:[[ConsoleLine alloc] initWithText:text
	                                                 outtime:lastmillis]
	[conlines insertObject:[ConsoleLine lineWithText:text
	                                         outtime:lastmillis]
	               atIndex:0];

	puts(text.UTF8String);
#ifndef OF_WINDOWS
	fflush(stdout);
#endif
}
131
132
133
134
135
136
137
138
139


140
141
142
143
144
145
146
108
109
110
111
112
113
114


115
116
117
118
119
120
121
122
123







-
-
+
+








void
keymap(OFString *code, OFString *key, OFString *action)
{
	if (keyMappings == nil)
		keyMappings = [[OFMutableArray alloc] init];

	KeyMapping *mapping =
	    [[KeyMapping alloc] initWithCode:code.cube_intValue name:key];
	KeyMapping *mapping = [KeyMapping mappingWithCode:code.cube_intValue
	                                             name:key];
	mapping.action = action;
	[keyMappings addObject:mapping];
}
COMMAND(keymap, ARG_3STR)

void
bindkey(OFString *key, OFString *action)