Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5243 in orxonox.OLD for trunk/src/lib/shell/shell_input.cc


Ignore:
Timestamp:
Sep 24, 2005, 7:43:08 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: now it is possible to get old commands from the List

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_input.cc

    r5237 r5243  
    4848  this->inputLine = new char[1];
    4949  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;
    5154  this->delayed = 0;
    5255  this->setRepeatDelay(.3, .05);
     
    6972  delete this->completion;
    7073
    71   tIterator<char>* itH = this->inputHistory->getIterator();
    72   char* histEl = itH->firstElement();
     74  char* histEl = this->historyIT->firstElement();
    7375  while (histEl != NULL)
    7476  {
    7577    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;
    8082}
    8183
     
    164166  char* newCommand = new char[strlen(this->inputLine)+1];
    165167  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  }
    167183
    168184  ShellCommandBase::execute(this->inputLine);
     
    171187
    172188  return false;
     189}
     190
     191
     192/**
     193 * moves one entry up in the history.
     194 */
     195void 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 */
     220void 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  }
    173232}
    174233
     
    228287    else if (event.type == SDLK_F2)
    229288      this->debug();
     289    else if (event.type == SDLK_UP)
     290      this->historyMoveUp();
     291    else if (event.type == SDLK_DOWN)
     292      this->historyMoveDown();
    230293    else if (event.type == SDLK_TAB)
    231294      this->completion->autoComplete();
Note: See TracChangeset for help on using the changeset viewer.