Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 2, 2006, 6:24:44 PM (18 years ago)
Author:
bensch
Message:

orxonox/new_class_id: moving through the Text with a cursor works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/shell/shell_input.cc

    r9861 r9865  
    4545    this->pressedKey = SDLK_FIRST;
    4646
    47     this->inputLine = "";
    4847    this->historyIT = ShellInput::history.begin();
    4948    this->setHistoryLength(50);
     
    5655    {
    5756      //if (!this->isEventSubscribed(ES_SHELL, i))
    58         this->subscribeEvent(ES_SHELL, i);
     57      this->subscribeEvent(ES_SHELL, i);
    5958    }
    6059    // unsubscribe unused TODO improve.
     
    6362    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
    6463    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    65 
    6664  }
    6765
     
    9088  void ShellInput::flush()
    9189  {
    92     this->inputLine.clear();
    93     this->setText(this->inputLine);
     90    this->inputLineBegin.clear();
     91    this->inputLineEnd.clear();
     92    this->clear();
    9493  }
    9594
     
    10099  void ShellInput::setInputText(const std::string& text)
    101100  {
    102     this->inputLine = text;
    103     this->setText(this->inputLine);
     101    this->inputLineBegin = text;
     102    this->inputLineEnd.clear();
     103    this->setText(text);
    104104  }
    105105
     
    117117    }
    118118
    119     this->inputLine += character;
    120     this->setText(this->inputLine);
     119    this->inputLineBegin += character;
     120    this->setText(this->inputLineBegin + this->inputLineEnd);
    121121  }
    122122
     
    133133    }
    134134
    135     this->inputLine += characters;
    136     this->setText(this->inputLine);
     135    this->inputLineBegin += characters;
     136    this->setText(this->inputLineBegin + this->inputLineEnd);
    137137  }
    138138
     
    148148      this->historyScrolling = false;
    149149    }
    150     if (this->inputLine.size() < characterCount)
    151       characterCount = this->inputLine.size();
    152 
    153     this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size());
    154     this->setText(this->inputLine);
     150    if (this->inputLineBegin.size() < characterCount)
     151      characterCount = this->inputLineBegin.size();
     152
     153    this->inputLineBegin.erase(this->inputLineBegin.size() - characterCount, this->inputLineBegin.size());
     154    this->setText(this->inputLineBegin + this->inputLineEnd);
    155155  }
    156156
     
    161161  bool ShellInput::executeCommand()
    162162  {
    163     DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
    164 
    165     if (this->inputLine.empty())
     163    if (this->getInput().empty())
    166164      return false;
    167 
    168     ShellCommand::execute(this->inputLine);
     165    DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str());
     166
     167    ShellCommand::execute(this->getInput());
    169168
    170169    // removing the eventually added Entry (from scrolling) to the List
     
    176175
    177176    // adding the new Command to the History
    178     if (history.empty() || history.back() != this->inputLine)
    179       this->history.push_back(this->inputLine);
     177    if (history.empty() || history.back() != this->getInput())
     178      this->history.push_back(this->getInput());
    180179    if (this->history.size() > this->historyLength)
    181180    {
     
    196195    if (!this->historyScrolling)
    197196    {
    198       this->history.push_back(this->inputLine);
     197      this->history.push_back(this->getInput());
    199198      this->historyScrolling = true;
    200199      this->historyIT = --this->history.end();
     
    234233  }
    235234
     235  /**
     236   * @brief moves the cursor chars Characters to the right.
     237   * @param chars how much to move the cursor.
     238   */
     239  void ShellInput::moveCursor(int chars)
     240  {
     241    if (chars > 0)
     242    {
     243      printf("move cursor %d to the right\n", chars);
     244      if (chars >= (int) this->inputLineEnd.size())
     245        chars = inputLineEnd.size();
     246      this->inputLineBegin += this->inputLineEnd.substr(0, chars);
     247      this->inputLineEnd.erase(0, chars);
     248    }
     249    else if (chars < 0)
     250    {
     251      chars = -chars;
     252      printf("move cursor %d to the left\n", chars);
     253
     254      if (chars >= (int) this->inputLineBegin.size())
     255        chars = inputLineBegin.size();
     256      this->inputLineEnd = this->inputLineBegin.substr(this->inputLineBegin.size() - chars) + this->inputLineEnd;
     257      this->inputLineBegin.erase(this->inputLineBegin.size() - chars);
     258    }
     259  }
     260
    236261
    237262  /**
     
    244269    if (className.empty())
    245270    {
    246       PRINT(0)("Help for the most important Shell-commands\n");
    247       PRINT(0)("F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
    248       PRINT(0)("input order:\n");
    249       PRINT(0)("ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
    250       PRINT(0)("Alias [parameter]\n");
    251       PRINT(0)("- Also try 'help className'");
     271      PRINT(0)("== Help for the most important Shell-commands\n");
     272      PRINT(0)("  F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
     273      PRINT(0)("  input order:\n");
     274      PRINT(0)("   ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
     275      PRINT(0)("   Alias [parameter]\n");
     276      PRINT(0)("- Also try 'help className' or pushing 'TAB'\n");
    252277    }
    253278    else if (!className.empty() && functionName.empty())
     
    272297      {
    273298        case SDLK_BACKSPACE:
    274           this->removeCharacters(1);
    275           break;
     299        this->removeCharacters(1);
     300        break;
    276301        case SDLK_UP:
    277           this->historyMoveUp();
    278           break;
     302        this->historyMoveUp();
     303        break;
    279304        case SDLK_DOWN:
    280           this->historyMoveDown();
    281           break;
     305        this->historyMoveDown();
     306        break;
    282307        default:
    283           {
    284             if (likely(pressedKey < 127))
    285               this->addCharacter(this->pressedKey);
    286           }
     308        {
     309          if (likely(pressedKey < 127))
     310            this->addCharacter(this->pressedKey);
     311        }
    287312      }
    288313    }
     
    316341        this->pressedEvent = event.type;
    317342      }
     343      else if (event.type == SDLK_LEFT)
     344      {
     345        this->moveCursor(-1);
     346        this->pressedKey = event.type;
     347        this->pressedEvent = event.type;
     348      }
     349      else if (event.type == SDLK_RIGHT)
     350      {
     351        this->moveCursor(+1);
     352        this->pressedKey = event.type;
     353        this->pressedEvent = event.type;
     354      }
    318355      else if (event.type == SDLK_TAB)
    319356      {
    320         this->completion.autoComplete(this->inputLine);
    321         this->setText(this->inputLine);
     357        this->completion.autoComplete(this->inputLineBegin);
     358        this->setText(this->getInput());
    322359      }
    323360      else if (event.type == SDLK_BACKSPACE)
     
    328365        this->removeCharacters(1);
    329366      }
     367      else if (event.type == SDLK_DELETE)
     368      {
     369        if (!this->inputLineEnd.empty())
     370        {
     371          this->inputLineEnd.erase(0, 1);
     372          this->setText(this->getInput());
     373        }
     374      }
    330375      else if (event.type == SDLK_RETURN)
    331376      {
Note: See TracChangeset for help on using the changeset viewer.