void LuaConsole::OnEnter(const std::string &text) { if (!text.empty()) ExecOrContinue(text); m_completionList.clear(); Pi::console->SelectWidget(m_entry); m_scroller->SetScrollPosition(1.0f); }
void LuaConsole::OnKeyPressed(const SDL_keysym *sym) { // XXX totally horrible doing this on every key press ResizeRequest(); if ((sym->sym == SDLK_UP) || (sym->sym == SDLK_DOWN)) { if (m_historyPosition == -1) { if (sym->sym == SDLK_UP) { m_historyPosition = (m_statementHistory.size() - 1); if (m_historyPosition != -1) { m_stashedStatement = m_entryField->GetText(); m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } else { if (sym->sym == SDLK_DOWN) { ++m_historyPosition; if (m_historyPosition >= int(m_statementHistory.size())) { m_historyPosition = -1; m_entryField->SetText(m_stashedStatement); m_stashedStatement.clear(); ResizeRequest(); } else { m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } else { if (m_historyPosition > 0) { --m_historyPosition; m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } } // CTRL+U clears the current command if ((sym->sym == SDLK_u) && (sym->mod & KMOD_CTRL)) { m_stashedStatement.clear(); m_entryField->SetText(""); m_historyPosition = -1; ResizeRequest(); } if (((sym->unicode == '\n') || (sym->unicode == '\r')) && ((sym->mod & KMOD_CTRL) == 0)) { ExecOrContinue(); } }
void LuaConsole::OnKeyPressed(const SDL_keysym *sym) { // XXX totally horrible doing this on every key press ResizeRequest(); if ((sym->sym == SDLK_UP) || (sym->sym == SDLK_DOWN)) { if (m_historyPosition == -1) { if (sym->sym == SDLK_UP) { m_historyPosition = (m_statementHistory.size() - 1); if (m_historyPosition != -1) { m_stashedStatement = m_entryField->GetText(); m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } else { if (sym->sym == SDLK_DOWN) { ++m_historyPosition; if (m_historyPosition >= int(m_statementHistory.size())) { m_historyPosition = -1; m_entryField->SetText(m_stashedStatement); m_stashedStatement.clear(); ResizeRequest(); } else { m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } else { if (m_historyPosition > 0) { --m_historyPosition; m_entryField->SetText(m_statementHistory[m_historyPosition]); ResizeRequest(); } } } } // CTRL+U clears the current command if ((sym->sym == SDLK_u) && (sym->mod & KMOD_CTRL)) { m_stashedStatement.clear(); m_entryField->SetText(""); m_historyPosition = -1; ResizeRequest(); } if (sym->sym == SDLK_TAB) { if (m_completionList.empty()) { UpdateCompletion(m_entryField->GetText()); } if (!m_completionList.empty()) { // We still need to test whether it failed or not. if (sym->mod & KMOD_SHIFT) { if (m_currentCompletion == 0) m_currentCompletion = m_completionList.size(); m_currentCompletion--; } else { m_currentCompletion++; if (m_currentCompletion == m_completionList.size()) m_currentCompletion = 0; } m_entryField->SetText(m_precompletionStatement + m_completionList[m_currentCompletion]); ResizeRequest(); } } else if (!m_completionList.empty() && (sym->sym < SDLK_NUMLOCK || sym->sym > SDLK_COMPOSE)) { m_completionList.clear(); } if (((sym->unicode == '\n') || (sym->unicode == '\r')) && ((sym->mod & KMOD_CTRL) == 0)) { ExecOrContinue(); } }