Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5243 in orxonox.OLD for trunk


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

Location:
trunk/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell.h

    r5208 r5243  
    33 * Definition of a on-screen-shell
    44 *
    5  * @todo check for smooth deletion process
    65 * @todo Buffer Display in different Colors for different debug mode.
    76 */
  • trunk/src/lib/shell/shell_command.h

    r5207 r5243  
    22 * @file shell_command.h
    33 * Definition of a on-screen-shell
     4 *
     5 * @todo also take Static functions
    46*/
    57
  • 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();
  • trunk/src/lib/shell/shell_input.h

    r5208 r5243  
    1515// FORWARD DECLARATION
    1616template<class T> class tList;
     17template<class T> class tIterator;
    1718class ShellCompletion;
    1819
     
    3536  void setRepeatDelay(float repeatDelay, float repeatRate);
    3637  bool executeCommand();
     38
     39  void historyMoveUp();
     40  void historyMoveDown();
     41
    3742  void help(const char* className = "", const char* function = "");
    3843
     
    4449   ShellCompletion*         completion;             //!< The Completion Interface.
    4550
     51
    4652   char*                    inputLine;              //!< the Char-Array of the Buffer @todo not needed anymore
    4753   float                    repeatRate;             //!< The Repeat-Delay.
     
    5056   int                      pressedKey;             //!< the pressed key that will be repeated.
    5157
    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.
    5362};
    5463
  • trunk/src/lib/util/list.h

    r5230 r5243  
    348348    T* seekElement(const T* element);
    349349    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();
    350357
    351358  private:
     
    514521
    515522
     523/**
     524 *  use it to move through the list without interfering with the iteration
     525 */
     526template<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 */
     543template<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
     555template<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
    516564#endif /* _LIST_H */
Note: See TracChangeset for help on using the changeset viewer.