- Timestamp:
- Oct 2, 2006, 6:24:44 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/shell
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/shell/shell_input.cc
r9861 r9865 45 45 this->pressedKey = SDLK_FIRST; 46 46 47 this->inputLine = "";48 47 this->historyIT = ShellInput::history.begin(); 49 48 this->setHistoryLength(50); … … 56 55 { 57 56 //if (!this->isEventSubscribed(ES_SHELL, i)) 58 57 this->subscribeEvent(ES_SHELL, i); 59 58 } 60 59 // unsubscribe unused TODO improve. … … 63 62 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP); 64 63 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN); 65 66 64 } 67 65 … … 90 88 void ShellInput::flush() 91 89 { 92 this->inputLine.clear(); 93 this->setText(this->inputLine); 90 this->inputLineBegin.clear(); 91 this->inputLineEnd.clear(); 92 this->clear(); 94 93 } 95 94 … … 100 99 void ShellInput::setInputText(const std::string& text) 101 100 { 102 this->inputLine = text; 103 this->setText(this->inputLine); 101 this->inputLineBegin = text; 102 this->inputLineEnd.clear(); 103 this->setText(text); 104 104 } 105 105 … … 117 117 } 118 118 119 this->inputLine += character;120 this->setText(this->inputLine );119 this->inputLineBegin += character; 120 this->setText(this->inputLineBegin + this->inputLineEnd); 121 121 } 122 122 … … 133 133 } 134 134 135 this->inputLine += characters;136 this->setText(this->inputLine );135 this->inputLineBegin += characters; 136 this->setText(this->inputLineBegin + this->inputLineEnd); 137 137 } 138 138 … … 148 148 this->historyScrolling = false; 149 149 } 150 if (this->inputLine .size() < characterCount)151 characterCount = this->inputLine .size();152 153 this->inputLine .erase(this->inputLine.size() - characterCount, this->inputLine.size());154 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); 155 155 } 156 156 … … 161 161 bool ShellInput::executeCommand() 162 162 { 163 DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 164 165 if (this->inputLine.empty()) 163 if (this->getInput().empty()) 166 164 return false; 167 168 ShellCommand::execute(this->inputLine); 165 DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str()); 166 167 ShellCommand::execute(this->getInput()); 169 168 170 169 // removing the eventually added Entry (from scrolling) to the List … … 176 175 177 176 // adding the new Command to the History 178 if (history.empty() || history.back() != this-> inputLine)179 this->history.push_back(this-> inputLine);177 if (history.empty() || history.back() != this->getInput()) 178 this->history.push_back(this->getInput()); 180 179 if (this->history.size() > this->historyLength) 181 180 { … … 196 195 if (!this->historyScrolling) 197 196 { 198 this->history.push_back(this-> inputLine);197 this->history.push_back(this->getInput()); 199 198 this->historyScrolling = true; 200 199 this->historyIT = --this->history.end(); … … 234 233 } 235 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("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("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 236 261 237 262 /** … … 244 269 if (className.empty()) 245 270 { 246 PRINT(0)(" Help for the most important Shell-commands\n");247 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");248 PRINT(0)(" input order:\n");249 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n");250 PRINT(0)(" Alias [parameter]\n");251 PRINT(0)("- Also try 'help className' ");271 PRINT(0)("== Help for the most important Shell-commands\n"); 272 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n"); 273 PRINT(0)(" input order:\n"); 274 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n"); 275 PRINT(0)(" Alias [parameter]\n"); 276 PRINT(0)("- Also try 'help className' or pushing 'TAB'\n"); 252 277 } 253 278 else if (!className.empty() && functionName.empty()) … … 272 297 { 273 298 case SDLK_BACKSPACE: 274 275 299 this->removeCharacters(1); 300 break; 276 301 case SDLK_UP: 277 278 302 this->historyMoveUp(); 303 break; 279 304 case SDLK_DOWN: 280 281 305 this->historyMoveDown(); 306 break; 282 307 default: 283 284 285 286 308 { 309 if (likely(pressedKey < 127)) 310 this->addCharacter(this->pressedKey); 311 } 287 312 } 288 313 } … … 316 341 this->pressedEvent = event.type; 317 342 } 343 else if (event.type == SDLK_LEFT) 344 { 345 this->moveCursor(-1); 346 this->pressedKey = event.type; 347 this->pressedEvent = event.type; 348 } 349 else if (event.type == SDLK_RIGHT) 350 { 351 this->moveCursor(+1); 352 this->pressedKey = event.type; 353 this->pressedEvent = event.type; 354 } 318 355 else if (event.type == SDLK_TAB) 319 356 { 320 this->completion.autoComplete(this->inputLine );321 this->setText(this-> inputLine);357 this->completion.autoComplete(this->inputLineBegin); 358 this->setText(this->getInput()); 322 359 } 323 360 else if (event.type == SDLK_BACKSPACE) … … 328 365 this->removeCharacters(1); 329 366 } 367 else if (event.type == SDLK_DELETE) 368 { 369 if (!this->inputLineEnd.empty()) 370 { 371 this->inputLineEnd.erase(0, 1); 372 this->setText(this->getInput()); 373 } 374 } 330 375 else if (event.type == SDLK_RETURN) 331 376 { -
branches/new_class_id/src/lib/shell/shell_input.h
r9715 r9865 37 37 38 38 /** @returns the inputLine */ 39 const std::string& getInput() const { return this->inputLine; };39 std::string getInput() const { return this->inputLineBegin + this->inputLineEnd; }; 40 40 41 41 // InputLine … … 55 55 void historyMoveDown(); 56 56 57 void moveCursor(int chars); 58 57 59 void help(const std::string& className = "", const std::string& function = ""); 58 60 … … 64 66 ShellCompletion completion; //!< The Completion Interface. 65 67 66 std::string inputLine; //!< the Char-Array of the Buffer 68 std::string inputLineBegin; //!< The Line up to the cursor. 69 std::string inputLineEnd; //!< The Line from the cursor on 70 67 71 float repeatRate; //!< The Repeat-Delay. 68 72 float repeatDelay; //!< The delay of the first Character of a given Character.
Note: See TracChangeset
for help on using the changeset viewer.