[Orxonox-commit 1268] r5986 - in code/branches/console/src/libraries/core: . input
scheusso at orxonox.net
scheusso at orxonox.net
Thu Oct 22 23:32:31 CEST 2009
Author: scheusso
Date: 2009-10-22 23:32:30 +0200 (Thu, 22 Oct 2009)
New Revision: 5986
Modified:
code/branches/console/src/libraries/core/IOConsole.cc
code/branches/console/src/libraries/core/Shell.cc
code/branches/console/src/libraries/core/Shell.h
code/branches/console/src/libraries/core/input/InputPrereqs.h
Log:
added a new feature to the IOConsole: you can now search the history (like in bash shells) with PgUP
just enter a few signs/characters of a command you once typed in and press PgUP to complete the command
if the found command is not the one you were looking for just press PgUP again
Modified: code/branches/console/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.cc 2009-10-22 11:36:48 UTC (rev 5985)
+++ code/branches/console/src/libraries/core/IOConsole.cc 2009-10-22 21:32:30 UTC (rev 5986)
@@ -126,9 +126,9 @@
else if (this->escapeSequence_ == "4~" || this->escapeSequence_ == "F")
this->buffer_->buttonPressed(KeyEvent(KeyCode::End, 0, 0));
else if (this->escapeSequence_ == "5~")
- this->buffer_->buttonPressed(KeyEvent(KeyCode::PageUp, 0, 0));
+ this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageUp, 0, 0));
else if (this->escapeSequence_ == "6~")
- this->buffer_->buttonPressed(KeyEvent(KeyCode::PageDown, 0, 0));
+ this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageDown, 0, 0));
else if (this->escapeSequence_.size() > 4)
// User probably very quickly pressed ESC and [
this->escapeMode_ = None;
Modified: code/branches/console/src/libraries/core/Shell.cc
===================================================================
--- code/branches/console/src/libraries/core/Shell.cc 2009-10-22 11:36:48 UTC (rev 5985)
+++ code/branches/console/src/libraries/core/Shell.cc 2009-10-22 21:32:30 UTC (rev 5986)
@@ -29,6 +29,7 @@
#include "Shell.h"
#include "util/OutputHandler.h"
+#include "util/StringUtils.h"
#include "CommandExecutor.h"
#include "CoreIncludes.h"
#include "ConfigValueIncludes.h"
@@ -131,6 +132,8 @@
this->inputBuffer_->registerListener(this, &Shell::history_down, KeyCode::Down);
this->inputBuffer_->registerListener(this, &Shell::scroll_up, KeyCode::PageUp);
this->inputBuffer_->registerListener(this, &Shell::scroll_down, KeyCode::PageDown);
+ this->inputBuffer_->registerListener(this, &Shell::history_search_up, KeyCode::AltPageUp);
+ this->inputBuffer_->registerListener(this, &Shell::history_search_down, KeyCode::AltPageDown);
}
void Shell::clearShell()
@@ -356,6 +359,42 @@
}
}
+ void Shell::history_search_up()
+ {
+ if (this->historyPosition_ == this->historyOffset_)
+ return;
+ unsigned int cursorPosition = this->getCursorPosition();
+ std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position
+ for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)
+ {
+ if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //search case insensitive
+ {
+ this->historyPosition_ = newPos;
+ this->inputBuffer_->set(this->getFromHistory());
+ this->setCursorPosition( cursorPosition );
+ return;
+ }
+ }
+ }
+
+ void Shell::history_search_down()
+ {
+ if (this->historyPosition_ == 0)
+ return;
+ unsigned int cursorPosition = this->getCursorPosition();
+ std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$
+ for (unsigned int newPos = this->historyPosition_-1; newPos>0; newPos--)
+ {
+ if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //sear$
+ {
+ this->historyPosition_ = newPos;
+ this->inputBuffer_->set(this->getFromHistory());
+ this->setCursorPosition( cursorPosition );
+ return;
+ }
+ }
+ }
+
void Shell::scroll_up()
{
if (this->scrollIterator_ != this->lines_.end())
Modified: code/branches/console/src/libraries/core/Shell.h
===================================================================
--- code/branches/console/src/libraries/core/Shell.h 2009-10-22 11:36:48 UTC (rev 5985)
+++ code/branches/console/src/libraries/core/Shell.h 2009-10-22 21:32:30 UTC (rev 5986)
@@ -128,6 +128,8 @@
void cursor_home();
void history_up();
void history_down();
+ void history_search_up();
+ void history_search_down();
void scroll_up();
void scroll_down();
void exit();
Modified: code/branches/console/src/libraries/core/input/InputPrereqs.h
===================================================================
--- code/branches/console/src/libraries/core/input/InputPrereqs.h 2009-10-22 11:36:48 UTC (rev 5985)
+++ code/branches/console/src/libraries/core/input/InputPrereqs.h 2009-10-22 21:32:30 UTC (rev 5986)
@@ -178,11 +178,13 @@
Home = OIS::KC_HOME, // Home on arrow keypad
Up = OIS::KC_UP, // UpArrow on arrow keypad
PageUp = OIS::KC_PGUP, // PgUp on arrow keypad
+ AltPageUp = OIS::KC_PGUP+1, // Alternative PgUp for the IOConsole
Left = OIS::KC_LEFT, // LeftArrow on arrow keypad
Right = OIS::KC_RIGHT, // RightArrow on arrow keypad
End = OIS::KC_END, // End on arrow keypad
Down = OIS::KC_DOWN, // DownArrow on arrow keypad
PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad
+ AltPageDown = OIS::KC_END-1, // Alternative PgUp for IOConsole
Insert = OIS::KC_INSERT, // Insert on arrow keypad
Delete = OIS::KC_DELETE, // Delete on arrow keypad
LeftWindows = OIS::KC_LWIN, // Left Windows key
@@ -285,11 +287,11 @@
"Home",
"UP",
"PageUp",
- "",
+ "", // used for AltPageUp
"Left",
"",
"Right",
- "",
+ "", // used for AltPageDown
"End", "Down", "PageDown", "Insert", "Delete",
"","","","","","","",
"LeftWindows", "RightWindows", "Apps",
More information about the Orxonox-commit
mailing list