Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5245 in orxonox.OLD for trunk/src/lib


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

orxonox/trunk: autoCompletion now gives a very nice output

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

Legend:

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

    r5227 r5245  
    5454  // register the shell at the ShellBuffer
    5555  ShellBuffer::getInstance()->registerShell(this);
    56 
     56  // EVENT-Handler subscription of '`' to all States.
     57  EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
    5758
    5859  // Element2D and generals
     
    7273  this->rebuildText();
    7374
    74   // EVENT-Handler subscription of '`' to all States.
    75   EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
    7675}
    7776
  • trunk/src/lib/shell/shell.h

    r5243 r5245  
    44 *
    55 * @todo Buffer Display in different Colors for different debug mode.
     6 * @todo move up and down in Buffer
    67 */
    78
  • trunk/src/lib/shell/shell_completion.cc

    r5197 r5245  
    6060 * autocompletes the Shell's inputLine
    6161 * @returns true, if a result was found, false otherwise
    62  *
    63  * @todo implement it!!
    6462 */
    6563bool ShellCompletion::autoComplete(ShellInput* input)
     
    169167  if (clList != NULL)
    170168  {
    171     if (!this->addToCompleteList(clList, classBegin))
     169    if (!this->addToCompleteList(clList, classBegin, SHELLC_CLASS))
    172170      return false;
    173171  }
     
    190188  if (boList != NULL)
    191189  {
    192     //printf("%s\n", boList->firstElement()->getName());
    193     if (!this->addToCompleteList(boList, objectBegin))
     190    SHELLC_TYPE type = SHELLC_OBJECT;
     191    if (classID == CL_SHELL_COMMAND_CLASS)
     192      type = SHELLC_CLASS;
     193    if (!this->addToCompleteList(boList, objectBegin, type))
    194194      return false;
    195195  }
     
    211211  ShellCommandClass::getCommandListOfClass(ClassList::IDToString(classID), &fktList);
    212212  //printf("%s\n", boList->firstElement()->getName());
    213   if (!this->addToCompleteList(&fktList, functionBegin))
     213  if (!this->addToCompleteList(&fktList, functionBegin, SHELLC_FUNCTION))
    214214    return false;
    215215  return true;
     
    228228  ShellCommandClass::getCommandListOfAlias(&aliasList);
    229229  //printf("%s\n", boList->firstElement()->getName());
    230   if (!this->addToCompleteList(&aliasList, aliasBegin))
     230  if (!this->addToCompleteList(&aliasList, aliasBegin, SHELLC_ALIAS))
    231231    return false;
    232232  return true;
     
    259259  tIterator<ShellC_Element>* charIterator = completionList->getIterator();
    260260  ShellC_Element* charElem = charIterator->firstElement();
     261  SHELLC_TYPE changeType = SHELLC_NONE;
    261262  while (charElem != NULL)
    262263  {
    263     PRINTF(0)(displayAs, charElem->name);
     264    if (charElem->type != changeType)
     265    {
     266      if (changeType != SHELLC_NONE)
     267        PRINT(0)("\n");
     268      PRINT(0)("%s: ", ShellCompletion::typeToString(charElem->type));
     269      changeType = charElem->type;
     270    }
     271    PRINTF(0)("%s ", charElem->name);
    264272    for (unsigned int i = inputLenght; i < addLength; i++)
    265273      if (addString[i] != charElem->name[i])
    266274      {
    267275       addLength = i;
    268        break;
     276//       break;
    269277      }
    270278    charElem = charIterator->nextElement();
    271279  }
    272280  delete charIterator;
     281  PRINT(0)("\n");
    273282
    274283  if (addLength >= inputLenght)
     
    301310 * !! The strings MUST NOT be deleted !!
    302311 */
    303 bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin)
     312bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type)
    304313{
    305314  if (inputList == NULL || completionBegin == NULL)
     
    317326      ShellC_Element* newElem = new ShellC_Element;
    318327      newElem->name = enumString;
     328      newElem->type = type;
    319329      this->completionList->add(newElem);
    320330    }
     
    332342 * !! The strings MUST NOT be deleted !!
    333343 */
    334 bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin)
     344bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type)
    335345{
    336346  if (inputList == NULL || completionBegin == NULL)
     
    348358      ShellC_Element* newElem = new ShellC_Element;
    349359      newElem->name = enumBO->getName();
     360      newElem->type = type;
    350361      this->completionList->add(newElem);
    351       printf("%s\n",enumBO->getName());
    352362    }
    353363    enumBO = iterator->nextElement();
     
    378388  this->completionList = new tList<ShellC_Element>;
    379389}
     390
     391const char* ShellCompletion::typeToString(SHELLC_TYPE type)
     392{
     393  switch (type)
     394  {
     395    default:// SHELLC_NONE
     396      return "error";
     397    case  SHELLC_CLASS:
     398      return "class";
     399    case SHELLC_OBJECT:
     400      return "object";
     401    case SHELLC_FUNCTION:
     402      return "function";
     403    case SHELLC_ALIAS:
     404      return "alias";
     405  }
     406}
  • trunk/src/lib/shell/shell_completion.h

    r5197 r5245  
    4848  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    4949
    50   bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin);
    51   bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin);
     50  bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type);
     51  bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5252  void emptyCompletionList();
     53
     54  static const char* ShellCompletion::typeToString(SHELLC_TYPE type);
    5355
    5456 private:
  • trunk/src/lib/shell/shell_input.cc

    r5244 r5245  
    5050  this->history = new tList<char>;
    5151  this->historyIT = this->history->getIterator();
    52   this->historyLength = 10;
     52  this->setHistoryLength(50);
    5353  this->historyScrolling = false;
    5454  this->delayed = 0;
  • trunk/src/lib/shell/shell_input.h

    r5244 r5245  
    11/*!
    22 * @file shell_input.h
    3  * @brief Definition of ...
    4  * @todo AutoCompletion should print nice output
    5  * @todo move up and down in Buffer
    6  * @todo display old shell Commands
     3 * @brief Shell Input is an InputLine for the Shell.
    74*/
    85
     
    1815class ShellCompletion;
    1916
    20 
    21 //! A class for ...
     17//! An InputLine for the Shell
     18/**
     19 * The ShellInput has the ability to catch and display user input.
     20 * The ShellInput is auto-completed after the user presses [TAB]
     21 * The ShellInput is executed (and sent back to the Application) on Pressing [ENTER]
     22 * [UP] and [DOWN] move through the history of allready given commands.
     23 */
    2224class ShellInput : public Text,  public EventListener {
    2325
     
    3840  bool executeCommand();
    3941
     42  /** sets the count of the History's entries */
     43  void setHistoryLength(unsigned int historyLength) { this->historyLength = historyLength; };
    4044  void historyMoveUp();
    4145  void historyMoveDown();
     
    5054   ShellCompletion*         completion;             //!< The Completion Interface.
    5155
    52 
    53    char*                    inputLine;              //!< the Char-Array of the Buffer @todo not needed anymore
     56   char*                    inputLine;              //!< the Char-Array of the Buffer
    5457   float                    repeatRate;             //!< The Repeat-Delay.
    5558   float                    repeatDelay;            //!< The delay of the first Character of a given Character.
Note: See TracChangeset for help on using the changeset viewer.