Changeset 5243 in orxonox.OLD for trunk/src/lib/shell/shell_input.cc
- Timestamp:
- Sep 24, 2005, 7:43:08 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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();
Note: See TracChangeset
for help on using the changeset viewer.