Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5244 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Sep 24, 2005, 8:06:05 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: scrolling back through the Shell's History works

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

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

    r5243 r5244  
    108108
    109109/**
     110 * sets the entire text of the InputLine to text
     111 * @param text the new Text to set as InputLine
     112 */
     113void ShellInput::setInputText(const char* text)
     114{
     115  delete[] this->inputLine;
     116  if (text == NULL)
     117  {
     118    this->inputLine = new char[1];
     119    this->inputLine[0] = '\0';
     120  }
     121  else
     122  {
     123    this->inputLine = new char[strlen(text)+1];
     124    strcpy(this->inputLine, text);
     125  }
     126  this->setText(this->inputLine, true);
     127}
     128
     129
     130/**
    110131 * adds one character to the inputLine
    111132 * @param character the character to add to the inputLine
     
    113134void ShellInput::addCharacter(char character)
    114135{
     136  if (this->historyScrolling)
     137  {
     138    delete[] this->history->lastElement();
     139    this->history->remove(this->history->lastElement());
     140    this->historyScrolling = false;
     141  }
     142
    115143  char* addCharLine = new char[strlen(this->inputLine)+2];
    116144
     
    127155void ShellInput::addCharacters(const char* characters)
    128156{
     157  if (this->historyScrolling)
     158  {
     159    delete[] this->history->lastElement();
     160    this->history->remove(this->history->lastElement());
     161    this->historyScrolling = false;
     162  }
     163
    129164  char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1];
    130165
     
    141176void ShellInput::removeCharacters(unsigned int characterCount)
    142177{
     178  if (this->historyScrolling)
     179  {
     180    delete[] this->history->lastElement();
     181    this->history->remove(this->history->lastElement());
     182    this->historyScrolling = false;
     183  }
     184
    143185  if (strlen(this->inputLine) == 0)
    144186    return;
     
    171213  {
    172214    delete[] this->history->lastElement();
     215    this->history->remove(this->history->lastElement());
    173216    this->historyScrolling = false;
    174217  }
     
    197240  if (!this->historyScrolling)
    198241  {
    199     char* newCommand = new char[strlen(this->inputLine)+1];
    200     strcpy(newCommand, this->inputLine);
    201     this->history->add(newCommand);
     242    char* currentText = new char[strlen(this->inputLine)+1];
     243    strcpy(currentText, this->inputLine);
     244    this->history->add(currentText);
    202245    this->historyScrolling = true;
    203246    this->historyIT->lastElement();
     
    210253  {
    211254    this->flush();
    212     this->addCharacters(prevElem);
    213   }
    214 
     255    this->setInputText(prevElem);
     256  }
    215257}
    216258
     
    228270  {
    229271    this->flush();
    230     this->addCharacters(nextElem);
     272    this->setInputText(nextElem);
    231273  }
    232274}
     
    301343    else if (event.type == SDLK_RETURN)
    302344      this->executeCommand();
    303     /*
    304     else if (event.type == SDLK_UP)
    305     {
    306 //      this->flushInputLine();
    307     tIterator<char>* iterator = this->commandList->getIterator();
    308     char* command = iterator->lastElement();
    309     while (command)
    310     {
    311     if (!strcmp (command, inputLine))
    312     {
    313     inputLine = iterator->prevElement();
    314     return;
    315   }
    316     command = iterator->prevElement();
    317   }
    318     inputLine = iterator->lastElement();
    319   }
    320     */
     345    // any other keyboard key
    321346    else if (likely(event.type < 127))
    322347    {
  • trunk/src/lib/shell/shell_input.h

    r5243 r5244  
    3131  // InputLine
    3232  void flush();
     33  void setInputText(const char* text);
    3334  void addCharacter(char character);
    3435  void addCharacters(const char* characters);
Note: See TracChangeset for help on using the changeset viewer.