Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

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

    r8339 r9869  
    2424#include "compiler.h"
    2525#include "key_names.h"
     26
    2627
    2728namespace OrxShell
     
    3132  ->setAlias("help");
    3233
     34  ObjectListDefinition(ShellInput);
    3335
    3436  /**
     
    3941      : Text ("")
    4042  {
     43    this->registerObject(this, ShellInput::_objectList);
     44
    4145    this->pressedKey = SDLK_FIRST;
    42     this->setClassID(CL_SHELL_INPUT, "ShellInput");
    43 
    44     this->inputLine = "";
     46
    4547    this->historyIT = ShellInput::history.begin();
    4648    this->setHistoryLength(50);
     
    5355    {
    5456      //if (!this->isEventSubscribed(ES_SHELL, i))
    55         this->subscribeEvent(ES_SHELL, i);
     57      this->subscribeEvent(ES_SHELL, i);
    5658    }
    5759    // unsubscribe unused TODO improve.
     
    6062    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
    6163    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    62 
    6364  }
    6465
     
    8788  void ShellInput::flush()
    8889  {
    89     this->inputLine.clear();
    90     this->setText(this->inputLine);
     90    this->inputLineBegin.clear();
     91    this->inputLineEnd.clear();
     92    this->clear();
    9193  }
    9294
     
    9799  void ShellInput::setInputText(const std::string& text)
    98100  {
    99     this->inputLine = text;
    100     this->setText(this->inputLine);
     101    this->inputLineBegin = text;
     102    this->inputLineEnd.clear();
     103    this->setText(text);
    101104  }
    102105
     
    114117    }
    115118
    116     this->inputLine += character;
    117     this->setText(this->inputLine);
     119    this->inputLineBegin += character;
     120    this->setText(this->inputLineBegin + this->inputLineEnd);
    118121  }
    119122
     
    130133    }
    131134
    132     this->inputLine += characters;
    133     this->setText(this->inputLine);
     135    this->inputLineBegin += characters;
     136    this->setText(this->inputLineBegin + this->inputLineEnd);
    134137  }
    135138
     
    145148      this->historyScrolling = false;
    146149    }
    147     if (this->inputLine.size() < characterCount)
    148       characterCount = this->inputLine.size();
    149 
    150     this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size());
    151     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);
    152155  }
    153156
     
    158161  bool ShellInput::executeCommand()
    159162  {
    160     ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
    161 
    162     if (this->inputLine.empty())
     163    if (this->getInput().empty())
    163164      return false;
    164 
    165     ShellCommand::execute(this->inputLine);
     165    DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str());
     166
     167    ShellCommand::execute(this->getInput());
    166168
    167169    // removing the eventually added Entry (from scrolling) to the List
     
    173175
    174176    // adding the new Command to the History
    175     if (history.empty() || history.back() != this->inputLine)
    176       this->history.push_back(this->inputLine);
     177    if (history.empty() || history.back() != this->getInput())
     178      this->history.push_back(this->getInput());
    177179    if (this->history.size() > this->historyLength)
    178180    {
     
    193195    if (!this->historyScrolling)
    194196    {
    195       this->history.push_back(this->inputLine);
     197      this->history.push_back(this->getInput());
    196198      this->historyScrolling = true;
    197199      this->historyIT = --this->history.end();
     
    231233  }
    232234
     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(5)("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(5)("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
    233261
    234262  /**
     
    237265  void ShellInput::help(const std::string& className, const std::string& functionName)
    238266  {
    239     printf("%s::%s\n", className.c_str(), functionName.c_str());
    240 
    241267    if (className.empty())
    242268    {
    243       PRINT(0)("Help for the most important Shell-commands\n");
    244       PRINT(0)("F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
    245       PRINT(0)("input order:\n");
    246       PRINT(0)("ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
    247       PRINT(0)("Alias [parameter]\n");
    248       PRINT(0)("- Also try 'help className'");
     269      PRINT(0)("== Help for the most important Shell-commands\n");
     270      PRINT(0)("  F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
     271      PRINT(0)("  input order:\n");
     272      PRINT(0)("   ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
     273      PRINT(0)("   Alias [parameter]\n");
     274      PRINT(0)("- Also try 'help className' or pushing 'TAB'\n");
    249275    }
    250276    else if (!className.empty() && functionName.empty())
     
    269295      {
    270296        case SDLK_BACKSPACE:
    271           this->removeCharacters(1);
    272           break;
     297        this->removeCharacters(1);
     298        break;
    273299        case SDLK_UP:
    274           this->historyMoveUp();
    275           break;
     300        this->historyMoveUp();
     301        break;
    276302        case SDLK_DOWN:
    277           this->historyMoveDown();
    278           break;
     303        this->historyMoveDown();
     304        break;
    279305        default:
    280           {
    281             if (likely(pressedKey < 127))
    282               this->addCharacter(this->pressedKey);
    283           }
     306        {
     307          if (likely(pressedKey < 127))
     308            this->addCharacter(this->pressedKey);
     309        }
    284310      }
    285311    }
     
    313339        this->pressedEvent = event.type;
    314340      }
     341      else if (event.type == SDLK_LEFT)
     342      {
     343        this->moveCursor(-1);
     344        this->pressedKey = event.type;
     345        this->pressedEvent = event.type;
     346      }
     347      else if (event.type == SDLK_RIGHT)
     348      {
     349        this->moveCursor(+1);
     350        this->pressedKey = event.type;
     351        this->pressedEvent = event.type;
     352      }
    315353      else if (event.type == SDLK_TAB)
    316354      {
    317         this->completion.autoComplete(this->inputLine);
    318         this->setText(this->inputLine);
     355        this->completion.autoComplete(this->inputLineBegin);
     356        this->setText(this->getInput());
    319357      }
    320358      else if (event.type == SDLK_BACKSPACE)
     
    325363        this->removeCharacters(1);
    326364      }
     365      else if (event.type == SDLK_DELETE)
     366      {
     367        if (!this->inputLineEnd.empty())
     368        {
     369          this->inputLineEnd.erase(0, 1);
     370          this->setText(this->getInput());
     371        }
     372      }
    327373      else if (event.type == SDLK_RETURN)
    328374      {
Note: See TracChangeset for help on using the changeset viewer.