Changeset 9869 in orxonox.OLD for trunk/src/lib/shell/shell_input.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_input.cc
r8339 r9869 24 24 #include "compiler.h" 25 25 #include "key_names.h" 26 26 27 27 28 namespace OrxShell … … 31 32 ->setAlias("help"); 32 33 34 ObjectListDefinition(ShellInput); 33 35 34 36 /** … … 39 41 : Text ("") 40 42 { 43 this->registerObject(this, ShellInput::_objectList); 44 41 45 this->pressedKey = SDLK_FIRST; 42 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 43 44 this->inputLine = ""; 46 45 47 this->historyIT = ShellInput::history.begin(); 46 48 this->setHistoryLength(50); … … 53 55 { 54 56 //if (!this->isEventSubscribed(ES_SHELL, i)) 55 57 this->subscribeEvent(ES_SHELL, i); 56 58 } 57 59 // unsubscribe unused TODO improve. … … 60 62 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP); 61 63 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN); 62 63 64 } 64 65 … … 87 88 void ShellInput::flush() 88 89 { 89 this->inputLine.clear(); 90 this->setText(this->inputLine); 90 this->inputLineBegin.clear(); 91 this->inputLineEnd.clear(); 92 this->clear(); 91 93 } 92 94 … … 97 99 void ShellInput::setInputText(const std::string& text) 98 100 { 99 this->inputLine = text; 100 this->setText(this->inputLine); 101 this->inputLineBegin = text; 102 this->inputLineEnd.clear(); 103 this->setText(text); 101 104 } 102 105 … … 114 117 } 115 118 116 this->inputLine += character;117 this->setText(this->inputLine );119 this->inputLineBegin += character; 120 this->setText(this->inputLineBegin + this->inputLineEnd); 118 121 } 119 122 … … 130 133 } 131 134 132 this->inputLine += characters;133 this->setText(this->inputLine );135 this->inputLineBegin += characters; 136 this->setText(this->inputLineBegin + this->inputLineEnd); 134 137 } 135 138 … … 145 148 this->historyScrolling = false; 146 149 } 147 if (this->inputLine .size() < characterCount)148 characterCount = this->inputLine .size();149 150 this->inputLine .erase(this->inputLine.size() - characterCount, this->inputLine.size());151 this->setText(this->inputLine );150 if (this->inputLineBegin.size() < characterCount) 151 characterCount = this->inputLineBegin.size(); 152 153 this->inputLineBegin.erase(this->inputLineBegin.size() - characterCount, this->inputLineBegin.size()); 154 this->setText(this->inputLineBegin + this->inputLineEnd); 152 155 } 153 156 … … 158 161 bool ShellInput::executeCommand() 159 162 { 160 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 161 162 if (this->inputLine.empty()) 163 if (this->getInput().empty()) 163 164 return false; 164 165 ShellCommand::execute(this->inputLine); 165 DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str()); 166 167 ShellCommand::execute(this->getInput()); 166 168 167 169 // removing the eventually added Entry (from scrolling) to the List … … 173 175 174 176 // adding the new Command to the History 175 if (history.empty() || history.back() != this-> inputLine)176 this->history.push_back(this-> inputLine);177 if (history.empty() || history.back() != this->getInput()) 178 this->history.push_back(this->getInput()); 177 179 if (this->history.size() > this->historyLength) 178 180 { … … 193 195 if (!this->historyScrolling) 194 196 { 195 this->history.push_back(this-> inputLine);197 this->history.push_back(this->getInput()); 196 198 this->historyScrolling = true; 197 199 this->historyIT = --this->history.end(); … … 231 233 } 232 234 235 /** 236 * @brief moves the cursor chars Characters to the right. 237 * @param chars how much to move the cursor. 238 */ 239 void ShellInput::moveCursor(int chars) 240 { 241 if (chars > 0) 242 { 243 PRINTF(5)("move cursor %d to the right\n", chars); 244 if (chars >= (int) this->inputLineEnd.size()) 245 chars = inputLineEnd.size(); 246 this->inputLineBegin += this->inputLineEnd.substr(0, chars); 247 this->inputLineEnd.erase(0, chars); 248 } 249 else if (chars < 0) 250 { 251 chars = -chars; 252 PRINTF(5)("move cursor %d to the left\n", chars); 253 254 if (chars >= (int) this->inputLineBegin.size()) 255 chars = inputLineBegin.size(); 256 this->inputLineEnd = this->inputLineBegin.substr(this->inputLineBegin.size() - chars) + this->inputLineEnd; 257 this->inputLineBegin.erase(this->inputLineBegin.size() - chars); 258 } 259 } 260 233 261 234 262 /** … … 237 265 void ShellInput::help(const std::string& className, const std::string& functionName) 238 266 { 239 printf("%s::%s\n", className.c_str(), functionName.c_str());240 241 267 if (className.empty()) 242 268 { 243 PRINT(0)(" Help for the most important Shell-commands\n");244 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");245 PRINT(0)(" input order:\n");246 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n");247 PRINT(0)(" Alias [parameter]\n");248 PRINT(0)("- Also try 'help className' ");269 PRINT(0)("== Help for the most important Shell-commands\n"); 270 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n"); 271 PRINT(0)(" input order:\n"); 272 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n"); 273 PRINT(0)(" Alias [parameter]\n"); 274 PRINT(0)("- Also try 'help className' or pushing 'TAB'\n"); 249 275 } 250 276 else if (!className.empty() && functionName.empty()) … … 269 295 { 270 296 case SDLK_BACKSPACE: 271 272 297 this->removeCharacters(1); 298 break; 273 299 case SDLK_UP: 274 275 300 this->historyMoveUp(); 301 break; 276 302 case SDLK_DOWN: 277 278 303 this->historyMoveDown(); 304 break; 279 305 default: 280 281 282 283 306 { 307 if (likely(pressedKey < 127)) 308 this->addCharacter(this->pressedKey); 309 } 284 310 } 285 311 } … … 313 339 this->pressedEvent = event.type; 314 340 } 341 else if (event.type == SDLK_LEFT) 342 { 343 this->moveCursor(-1); 344 this->pressedKey = event.type; 345 this->pressedEvent = event.type; 346 } 347 else if (event.type == SDLK_RIGHT) 348 { 349 this->moveCursor(+1); 350 this->pressedKey = event.type; 351 this->pressedEvent = event.type; 352 } 315 353 else if (event.type == SDLK_TAB) 316 354 { 317 this->completion.autoComplete(this->inputLine );318 this->setText(this-> inputLine);355 this->completion.autoComplete(this->inputLineBegin); 356 this->setText(this->getInput()); 319 357 } 320 358 else if (event.type == SDLK_BACKSPACE) … … 325 363 this->removeCharacters(1); 326 364 } 365 else if (event.type == SDLK_DELETE) 366 { 367 if (!this->inputLineEnd.empty()) 368 { 369 this->inputLineEnd.erase(0, 1); 370 this->setText(this->getInput()); 371 } 372 } 327 373 else if (event.type == SDLK_RETURN) 328 374 {
Note: See TracChangeset
for help on using the changeset viewer.