Differences From Artifact [a83084fb6c]:
- File src/console.m — part of check-in [cc7ebd7f79] at 2025-03-26 21:47:31 on branch trunk — Run newer version of clang-format (user: js, size: 5769) [annotate] [blame] [check-ins using]
To Artifact [1d463d8f9f]:
- File
src/console.m
— part of check-in
[75e920ae30]
at
2025-03-29 14:25:43
on branch trunk
— Switch from clang-format to manual formatting
clang-format does too many weird things. (user: js, size: 5733) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
14 15 16 17 18 19 20 | const int ndraw = 5; const int WORDWRAP = 80; int conskip = 0; bool saycommandon = false; static OFMutableString *commandbuf; | | | | | | | | | | | | 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 43 44 45 46 47 48 49 50 51 52 53 54 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 | const int ndraw = 5; const int WORDWRAP = 80; int conskip = 0; bool saycommandon = false; static OFMutableString *commandbuf; COMMAND(conskip, ARG_1INT, ^ (int n) { conskip += n; if (conskip < 0) conskip = 0; }) static void conline(OFString *sf, bool highlight) // add a line to the console buffer { OFMutableString *text; // constrain the buffer size if (conlines.count > 100) { text = [conlines.lastObject.text mutableCopy]; [conlines removeLastObject]; } else 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 lineWithText: text outtime: lastmillis] atIndex: 0]; puts(text.UTF8String); #ifndef OF_WINDOWS fflush(stdout); #endif } void conoutf(OFConstantString *format, ...) { va_list arguments; va_start(arguments, format); OFString *string = [[OFString alloc] initWithFormat: format arguments: arguments]; va_end(arguments); int n = 0; while (string.length > WORDWRAP) { conline([string substringToIndex: WORDWRAP], n++ != 0); string = [string substringFromIndex: WORDWRAP]; } conline(string, n != 0); } // render buffer taking into account time & scrolling void renderconsole() |
︙ | ︙ | |||
98 99 100 101 102 103 104 | (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2); } // keymap is defined externally in keymap.cfg static OFMutableArray<KeyMapping *> *keyMappings = nil; | | | | | | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2); } // keymap is defined externally in keymap.cfg static OFMutableArray<KeyMapping *> *keyMappings = nil; COMMAND(keymap, ARG_3STR, ^ (OFString *code, OFString *key, OFString *action) { if (keyMappings == nil) keyMappings = [[OFMutableArray alloc] init]; KeyMapping *mapping = [KeyMapping mappingWithCode: code.cube_intValue name: key]; mapping.action = action; [keyMappings addObject: mapping]; }) COMMAND(bind, ARG_2STR, ^ (OFString *key, OFString *action) { for (KeyMapping *mapping in keyMappings) { if ([mapping.name caseInsensitiveCompare: key] == OFOrderedSame) { mapping.action = action; return; } } conoutf(@"unknown key \"%@\"", key); |
︙ | ︙ | |||
139 140 141 142 143 144 145 | if (init == nil) init = @""; commandbuf = [init mutableCopy]; } | | | | | | 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 | if (init == nil) init = @""; commandbuf = [init mutableCopy]; } COMMAND(saycommand, ARG_VARI, ^ (OFString *init) { saycommand(init); }) COMMAND(mapmsg, ARG_1STR, ^ (OFString *s) { memset(hdr.maptitle, '\0', sizeof(hdr.maptitle)); strncpy(hdr.maptitle, s.UTF8String, 127); }) void pasteconsole() { [commandbuf appendString: @(SDL_GetClipboardText())]; } static OFMutableArray<OFString *> *vhistory; static int histpos = 0; COMMAND(history, ARG_1INT, ^ (int n) { static bool rec = false; if (!rec && n >= 0 && n < vhistory.count) { rec = true; execute(vhistory[vhistory.count - n - 1], true); rec = false; } |
︙ | ︙ | |||
222 223 224 225 226 227 228 | if (commandbuf.length > 0) { if (vhistory == nil) vhistory = [[OFMutableArray alloc] init]; if (vhistory.count == 0 || | | | | | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | if (commandbuf.length > 0) { 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: @"/"]) execute(commandbuf, true); else toserver(commandbuf); } saycommand(NULL); } else if (code == SDLK_ESCAPE) { saycommand(NULL); |
︙ | ︙ | |||
257 258 259 260 261 262 263 | } } void input(OFString *text) { if (saycommandon) | | | | | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | } } void input(OFString *text) { if (saycommandon) [commandbuf appendString: text]; } 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]; } |