void IConsoleGUIInit() { IConsoleResetHistoryPos(); _iconsole_mode = ICONSOLE_CLOSED; IConsoleLine::Reset(); memset(_iconsole_history, 0, sizeof(_iconsole_history)); IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision); IConsolePrint(CC_WHITE, "------------------------------------"); IConsolePrint(CC_WHITE, "use \"help\" for more information"); IConsolePrint(CC_WHITE, ""); IConsoleClearCommand(); }
void IConsoleGUIInit() { _iconsole_historypos = ICON_HISTORY_SIZE - 1; _iconsole_mode = ICONSOLE_CLOSED; IConsoleLine::Reset(); memset(_iconsole_history, 0, sizeof(_iconsole_history)); _iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it _iconsole_cmdline.max_bytes = ICON_CMDLN_SIZE; _iconsole_cmdline.max_chars = ICON_CMDLN_SIZE; IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision); IConsolePrint(CC_WHITE, "------------------------------------"); IConsolePrint(CC_WHITE, "use \"help\" for more information"); IConsolePrint(CC_WHITE, ""); IConsoleClearCommand(); }
/** * Navigate Up/Down in the history of typed commands * @param direction Go further back in history (+1), go to recently typed commands (-1) */ static void IConsoleHistoryNavigate(int direction) { if (_iconsole_history[0] == NULL) return; // Empty history int i = _iconsole_historypos + direction; /* watch out for overflows, just wrap around */ if (i < 0) i = ICON_HISTORY_SIZE - 1; if ((uint)i >= ICON_HISTORY_SIZE) i = 0; if (direction > 0) { if (_iconsole_history[i] == NULL) i = 0; } if (direction < 0) { while (i > 0 && _iconsole_history[i] == NULL) i--; } _iconsole_historypos = i; IConsoleClearCommand(); /* copy history to 'command prompt / bash' */ assert(_iconsole_history[i] != NULL && IsInsideMM(i, 0, ICON_HISTORY_SIZE)); ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_history[i], _iconsole_cmdline.max_bytes); UpdateTextBufferSize(&_iconsole_cmdline); }
virtual EventState OnKeyPress(uint16 key, uint16 keycode) { if (_focused_window != this) return ES_NOT_HANDLED; const int scroll_height = (this->height / this->line_height) - 1; switch (keycode) { case WKC_UP: IConsoleHistoryNavigate(1); this->SetDirty(); break; case WKC_DOWN: IConsoleHistoryNavigate(-1); this->SetDirty(); break; case WKC_SHIFT | WKC_PAGEDOWN: this->Scroll(-scroll_height); break; case WKC_SHIFT | WKC_PAGEUP: this->Scroll(scroll_height); break; case WKC_SHIFT | WKC_DOWN: this->Scroll(-1); break; case WKC_SHIFT | WKC_UP: this->Scroll(1); break; case WKC_BACKQUOTE: IConsoleSwitch(); break; case WKC_RETURN: case WKC_NUM_ENTER: { /* We always want the ] at the left side; we always force these strings to be left * aligned anyway. So enforce this in all cases by addding a left-to-right marker, * otherwise it will be drawn at the wrong side with right-to-left texts. */ IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf); const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf); IConsoleClearCommand(); if (cmd != NULL) IConsoleCmdExec(cmd); break; } case WKC_CTRL | WKC_RETURN: _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL; IConsoleResize(this); MarkWholeScreenDirty(); break; #ifdef WITH_COCOA case (WKC_META | 'V'): #endif case (WKC_CTRL | 'V'): if (InsertTextBufferClipboard(&_iconsole_cmdline)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; case (WKC_CTRL | 'L'): IConsoleCmdExec("clear"); break; #ifdef WITH_COCOA case (WKC_META | 'U'): #endif case (WKC_CTRL | 'U'): DeleteTextBufferAll(&_iconsole_cmdline); this->SetDirty(); break; case WKC_BACKSPACE: case WKC_DELETE: if (DeleteTextBufferChar(&_iconsole_cmdline, keycode)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME: if (MoveTextBufferPos(&_iconsole_cmdline, keycode)) { IConsoleResetHistoryPos(); this->SetDirty(); } break; default: if (IsValidChar(key, CS_ALPHANUMERAL)) { IConsoleWindow::scroll = 0; InsertTextBufferChar(&_iconsole_cmdline, key); IConsoleResetHistoryPos(); this->SetDirty(); } else { return ES_NOT_HANDLED; } break; } return ES_HANDLED; }
virtual EventState OnKeyPress(WChar key, uint16 keycode) { if (_focused_window != this) return ES_NOT_HANDLED; const int scroll_height = (this->height / this->line_height) - 1; switch (keycode) { case WKC_UP: IConsoleHistoryNavigate(1); this->SetDirty(); break; case WKC_DOWN: IConsoleHistoryNavigate(-1); this->SetDirty(); break; case WKC_SHIFT | WKC_PAGEDOWN: this->Scroll(-scroll_height); break; case WKC_SHIFT | WKC_PAGEUP: this->Scroll(scroll_height); break; case WKC_SHIFT | WKC_DOWN: this->Scroll(-1); break; case WKC_SHIFT | WKC_UP: this->Scroll(1); break; case WKC_BACKQUOTE: IConsoleSwitch(); break; case WKC_RETURN: case WKC_NUM_ENTER: { /* We always want the ] at the left side; we always force these strings to be left * aligned anyway. So enforce this in all cases by addding a left-to-right marker, * otherwise it will be drawn at the wrong side with right-to-left texts. */ IConsolePrintF(CC_COMMAND, LRM "] %s", _iconsole_cmdline.buf); const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf); IConsoleClearCommand(); if (cmd != NULL) IConsoleCmdExec(cmd); break; } case WKC_CTRL | WKC_RETURN: _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL; IConsoleResize(this); MarkWholeScreenDirty(); break; case (WKC_CTRL | 'L'): IConsoleCmdExec("clear"); break; default: if (_iconsole_cmdline.HandleKeyPress(key, keycode) != HKPR_NOT_HANDLED) { IConsoleWindow::scroll = 0; IConsoleResetHistoryPos(); this->SetDirty(); } else { return ES_NOT_HANDLED; } break; } return ES_HANDLED; }