equal
deleted
inserted
replaced
44 |
44 |
45 /* *************** * |
45 /* *************** * |
46 * end of header * |
46 * end of header * |
47 * *************** */ |
47 * *************** */ |
48 |
48 |
49 static void IConsoleClearCommand(void) |
49 static void IConsoleClearCommand() |
50 { |
50 { |
51 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE); |
51 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE); |
52 _iconsole_cmdline.length = 0; |
52 _iconsole_cmdline.length = 0; |
53 _iconsole_cmdline.width = 0; |
53 _iconsole_cmdline.width = 0; |
54 _iconsole_cmdline.caretpos = 0; |
54 _iconsole_cmdline.caretpos = 0; |
55 _iconsole_cmdline.caretxoffs = 0; |
55 _iconsole_cmdline.caretxoffs = 0; |
56 SetWindowDirty(FindWindowById(WC_CONSOLE, 0)); |
56 SetWindowDirty(FindWindowById(WC_CONSOLE, 0)); |
57 } |
57 } |
58 |
58 |
59 static inline void IConsoleResetHistoryPos(void) {_iconsole_historypos = ICON_HISTORY_SIZE - 1;} |
59 static inline void IConsoleResetHistoryPos() {_iconsole_historypos = ICON_HISTORY_SIZE - 1;} |
60 |
60 |
61 |
61 |
62 static void IConsoleHistoryAdd(const char *cmd); |
62 static void IConsoleHistoryAdd(const char *cmd); |
63 static void IConsoleHistoryNavigate(int direction); |
63 static void IConsoleHistoryNavigate(int direction); |
64 |
64 |
205 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
205 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
206 _iconsole_window_widgets, |
206 _iconsole_window_widgets, |
207 IConsoleWndProc, |
207 IConsoleWndProc, |
208 }; |
208 }; |
209 |
209 |
210 void IConsoleInit(void) |
210 void IConsoleInit() |
211 { |
211 { |
212 extern const char _openttd_revision[]; |
212 extern const char _openttd_revision[]; |
213 _iconsole_output_file = NULL; |
213 _iconsole_output_file = NULL; |
214 _icolour_def = 1; |
214 _icolour_def = 1; |
215 _icolour_err = 3; |
215 _icolour_err = 3; |
236 IConsoleStdLibRegister(); |
236 IConsoleStdLibRegister(); |
237 IConsoleClearCommand(); |
237 IConsoleClearCommand(); |
238 IConsoleHistoryAdd(""); |
238 IConsoleHistoryAdd(""); |
239 } |
239 } |
240 |
240 |
241 void IConsoleClearBuffer(void) |
241 void IConsoleClearBuffer() |
242 { |
242 { |
243 uint i; |
243 uint i; |
244 for (i = 0; i <= ICON_BUFFER; i++) { |
244 for (i = 0; i <= ICON_BUFFER; i++) { |
245 free(_iconsole_buffer[i]); |
245 free(_iconsole_buffer[i]); |
246 _iconsole_buffer[i] = NULL; |
246 _iconsole_buffer[i] = NULL; |
247 } |
247 } |
248 } |
248 } |
249 |
249 |
250 static void IConsoleClear(void) |
250 static void IConsoleClear() |
251 { |
251 { |
252 free(_iconsole_cmdline.buf); |
252 free(_iconsole_cmdline.buf); |
253 IConsoleClearBuffer(); |
253 IConsoleClearBuffer(); |
254 } |
254 } |
255 |
255 |
260 fwrite(string, strlen(string), 1, _iconsole_output_file); |
260 fwrite(string, strlen(string), 1, _iconsole_output_file); |
261 fwrite("\n", 1, 1, _iconsole_output_file); |
261 fwrite("\n", 1, 1, _iconsole_output_file); |
262 } |
262 } |
263 } |
263 } |
264 |
264 |
265 bool CloseConsoleLogIfActive(void) |
265 bool CloseConsoleLogIfActive() |
266 { |
266 { |
267 if (_iconsole_output_file != NULL) { |
267 if (_iconsole_output_file != NULL) { |
268 IConsolePrintF(_icolour_def, "file output complete"); |
268 IConsolePrintF(_icolour_def, "file output complete"); |
269 fclose(_iconsole_output_file); |
269 fclose(_iconsole_output_file); |
270 _iconsole_output_file = NULL; |
270 _iconsole_output_file = NULL; |
272 } |
272 } |
273 |
273 |
274 return false; |
274 return false; |
275 } |
275 } |
276 |
276 |
277 void IConsoleFree(void) |
277 void IConsoleFree() |
278 { |
278 { |
279 IConsoleClear(); |
279 IConsoleClear(); |
280 CloseConsoleLogIfActive(); |
280 CloseConsoleLogIfActive(); |
281 } |
281 } |
282 |
282 |
295 } |
295 } |
296 |
296 |
297 MarkWholeScreenDirty(); |
297 MarkWholeScreenDirty(); |
298 } |
298 } |
299 |
299 |
300 void IConsoleSwitch(void) |
300 void IConsoleSwitch() |
301 { |
301 { |
302 switch (_iconsole_mode) { |
302 switch (_iconsole_mode) { |
303 case ICONSOLE_CLOSED: { |
303 case ICONSOLE_CLOSED: { |
304 Window *w = AllocateWindowDesc(&_iconsole_window_desc); |
304 Window *w = AllocateWindowDesc(&_iconsole_window_desc); |
305 w->height = _screen.height / 3; |
305 w->height = _screen.height / 3; |
315 } |
315 } |
316 |
316 |
317 MarkWholeScreenDirty(); |
317 MarkWholeScreenDirty(); |
318 } |
318 } |
319 |
319 |
320 void IConsoleClose(void) {if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();} |
320 void IConsoleClose() {if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();} |
321 void IConsoleOpen(void) {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();} |
321 void IConsoleOpen() {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();} |
322 |
322 |
323 /** |
323 /** |
324 * Add the entered line into the history so you can look it back |
324 * Add the entered line into the history so you can look it back |
325 * scroll, etc. Put it to the beginning as it is the latest text |
325 * scroll, etc. Put it to the beginning as it is the latest text |
326 * @param cmd Text to be entered into the 'history' |
326 * @param cmd Text to be entered into the 'history' |