Changeset 5243 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Sep 24, 2005, 7:43:08 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell.h
r5208 r5243 3 3 * Definition of a on-screen-shell 4 4 * 5 * @todo check for smooth deletion process6 5 * @todo Buffer Display in different Colors for different debug mode. 7 6 */ -
trunk/src/lib/shell/shell_command.h
r5207 r5243 2 2 * @file shell_command.h 3 3 * Definition of a on-screen-shell 4 * 5 * @todo also take Static functions 4 6 */ 5 7 -
trunk/src/lib/shell/shell_input.cc
r5237 r5243 48 48 this->inputLine = new char[1]; 49 49 this->inputLine[0] = '\0'; 50 this->inputHistory = new tList<char>; 50 this->history = new tList<char>; 51 this->historyIT = this->history->getIterator(); 52 this->historyLength = 10; 53 this->historyScrolling = false; 51 54 this->delayed = 0; 52 55 this->setRepeatDelay(.3, .05); … … 69 72 delete this->completion; 70 73 71 tIterator<char>* itH = this->inputHistory->getIterator(); 72 char* histEl = itH->firstElement(); 74 char* histEl = this->historyIT->firstElement(); 73 75 while (histEl != NULL) 74 76 { 75 77 delete[] histEl; 76 histEl = itH->nextElement();77 } 78 delete itH;79 delete this-> inputHistory;78 histEl = this->historyIT->nextElement(); 79 } 80 delete this->historyIT; 81 delete this->history; 80 82 } 81 83 … … 164 166 char* newCommand = new char[strlen(this->inputLine)+1]; 165 167 strcpy(newCommand, this->inputLine); 166 this->inputHistory->add(newCommand); 168 169 // removing the eventually added Entry (from scrolling) to the List 170 if (this->historyScrolling) 171 { 172 delete[] this->history->lastElement(); 173 this->historyScrolling = false; 174 } 175 176 // adding the new Command to the History 177 this->history->add(newCommand); 178 if (this->history->getSize() > this->historyLength) 179 { 180 delete[] this->history->firstElement(); 181 this->history->remove(this->history->firstElement()); 182 } 167 183 168 184 ShellCommandBase::execute(this->inputLine); … … 171 187 172 188 return false; 189 } 190 191 192 /** 193 * moves one entry up in the history. 194 */ 195 void ShellInput::historyMoveUp() 196 { 197 if (!this->historyScrolling) 198 { 199 char* newCommand = new char[strlen(this->inputLine)+1]; 200 strcpy(newCommand, this->inputLine); 201 this->history->add(newCommand); 202 this->historyScrolling = true; 203 this->historyIT->lastElement(); 204 } 205 206 char* prevElem = this->historyIT->prevStep(); 207 if (prevElem == NULL) 208 return; 209 else 210 { 211 this->flush(); 212 this->addCharacters(prevElem); 213 } 214 215 } 216 217 /** 218 * moves one entry down in the history 219 */ 220 void ShellInput::historyMoveDown() 221 { 222 if (!this->historyScrolling) 223 return; 224 char* nextElem = this->historyIT->nextStep(); 225 if (nextElem == NULL) 226 return; 227 else 228 { 229 this->flush(); 230 this->addCharacters(nextElem); 231 } 173 232 } 174 233 … … 228 287 else if (event.type == SDLK_F2) 229 288 this->debug(); 289 else if (event.type == SDLK_UP) 290 this->historyMoveUp(); 291 else if (event.type == SDLK_DOWN) 292 this->historyMoveDown(); 230 293 else if (event.type == SDLK_TAB) 231 294 this->completion->autoComplete(); -
trunk/src/lib/shell/shell_input.h
r5208 r5243 15 15 // FORWARD DECLARATION 16 16 template<class T> class tList; 17 template<class T> class tIterator; 17 18 class ShellCompletion; 18 19 … … 35 36 void setRepeatDelay(float repeatDelay, float repeatRate); 36 37 bool executeCommand(); 38 39 void historyMoveUp(); 40 void historyMoveDown(); 41 37 42 void help(const char* className = "", const char* function = ""); 38 43 … … 44 49 ShellCompletion* completion; //!< The Completion Interface. 45 50 51 46 52 char* inputLine; //!< the Char-Array of the Buffer @todo not needed anymore 47 53 float repeatRate; //!< The Repeat-Delay. … … 50 56 int pressedKey; //!< the pressed key that will be repeated. 51 57 52 tList<char>* inputHistory; //!< The history of given commands. 58 tList<char>* history; //!< The history of given commands. 59 tIterator<char>* historyIT; 60 unsigned int historyLength; //!< The maximum length of the InputHistory. 61 bool historyScrolling; //!< true if we are scrolling through the history. 53 62 }; 54 63 -
trunk/src/lib/util/list.h
r5230 r5243 348 348 T* seekElement(const T* element); 349 349 T* iteratorElement(const tIterator<T>* iterator); 350 351 /** another way to iterate through the list 352 * !! THIS IS NOT MEANT FOR DELETION 353 */ 354 T* prevStep(); 355 T* nextStep(); 356 T* getCurrent(); 350 357 351 358 private: … … 514 521 515 522 523 /** 524 * use it to move through the list without interfering with the iteration 525 */ 526 template<class T> 527 inline T* tIterator<T>::nextStep () 528 { 529 if( unlikely(this->tmpEl == NULL || this->tmpEl->next == NULL)) 530 return NULL; 531 else 532 { 533 this->tmpEl = this->tmpEl->next; 534 return tmpEl->curr; 535 } 536 } 537 538 539 /** 540 * use it to move backwards through the list without interfering with the itereation 541 * @returns next list element 542 */ 543 template<class T> 544 inline T* tIterator<T>::prevStep () 545 { 546 if( unlikely(this->tmpEl == NULL || this->tmpEl->prev == NULL)) 547 return NULL; 548 else 549 { 550 this->tmpEl = this->tmpEl->prev; 551 return tmpEl->curr; 552 } 553 } 554 555 template<class T> 556 inline T* tIterator<T>::getCurrent() 557 { 558 if (likeley(this->tmpEl)) 559 return this->tmpEl->curr; 560 else 561 return NULL; 562 } 563 516 564 #endif /* _LIST_H */
Note: See TracChangeset
for help on using the changeset viewer.