Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7413 in orxonox.OLD for trunk/src/lib/shell/shell_completion.cc


Ignore:
Timestamp:
Apr 28, 2006, 12:54:04 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Shell Completes some Parameters nicely now

File:
1 edited

Legend:

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

    r7412 r7413  
    5757    std::string completeString = "";                 //< the string to complete.
    5858    unsigned int parameterBegin = 0;                 //< The SubString-entry, the Parameters begin.
     59    const ShellCommand* command = NULL;              //< The Command.
    5960
    6061
     
    8283    // OBJECT/FUNCTION COMPLETIONS
    8384    else if ((emptyComplete && inputSplits.size() == 1) ||
    84               (!emptyComplete && inputSplits.size() == 2))
     85             (!emptyComplete && inputSplits.size() == 2))
    8586    {
    8687      classID = ClassList::StringToID(inputSplits.getString(0));
     
    99100
    100101    // Looking for ParameterCompletions.
     102    if (completeType == NullCompletion)
     103    {
     104      if ((command = ShellCommand::getCommandFromInput(input)) != NULL)
     105        completeType |= ParamCompletion;
     106    }
    101107
    102108    if (completeType & ClassCompletion)
     
    108114    if (completeType & AliasCompletion)
    109115      this->aliasComplete(completeString);
    110 
    111     if (completeType == NullCompletion)
    112     {
    113       const ShellCommand* sc = ShellCommand::getCommand(inputSplits[2], inputSplits[0]);
    114       if (sc != NULL)
    115       {
    116         std::vector<std::string> completed;
    117         sc->getCompletorPlugin(0)->addToCompleteList(completed, inputSplits[inputSplits.size()-1]);
    118         for (unsigned int i = 0; i < completed.size(); i++)
    119           this->completionList.push_back(CompletionElement(completed[i], ParamCompletion));
    120       }
    121     }
     116    if (completeType & ParamCompletion)
     117      this->paramComplete(completeString, command);
     118
    122119
    123120
     
    157154    std::list<std::string> fktList;
    158155    ShellCommandClass::getCommandListOfClass(className, fktList);
    159     //printf("%s\n", boList->firstElement()->getName());
    160156    if (!this->addToCompleteList(fktList, commandBegin, FunctionCompletion))
    161157      return false;
     
    172168    std::list<std::string> aliasList;
    173169    ShellCommandAlias::getCommandListOfAlias(aliasList);
    174     //printf("%s\n", boList->firstElement()->getName());
    175170    if (!this->addToCompleteList(aliasList, aliasBegin, AliasCompletion))
    176171      return false;
    177172    return true;
     173  }
     174
     175  /**
     176   * @brief completes Parameters.
     177   * @param paramBegin: Begin of the Parameters.
     178   * @returns true on succes, false if something went wrong
     179   */
     180  bool ShellCompletion::paramComplete(const std::string& paramBegin, const ShellCommand* command)
     181  {
     182    std::vector<std::string> completed;
     183    command->getCompletorPlugin(0)->addToCompleteList(completed, paramBegin);
     184      for (unsigned int i = 0; i < completed.size(); i++)
     185        this->completionList.push_back(CompletionElement(completed[i], ParamCompletion));
    178186  }
    179187
     
    197205    CompletionElement addElem = completionList.front();
    198206    const std::string& addString = addElem.name;
    199     unsigned int addLength = 0;
     207    unsigned int addLength = addString.size();
    200208    unsigned int inputLenght = begin.size();
    201209
    202     // Determin the longest Match
    203     addLength = addString.size();
    204 
     210    // Determin the longest Match (starting with the first candidate in full length).
    205211    CompletionType changeType = NullCompletion;
    206212    std::vector<CompletionElement>::iterator charIT;
    207213    for (charIT = completionList.begin(); charIT != completionList.end(); charIT++)
    208214    {
     215      printf("== %s\n", (*charIT).name.c_str());
    209216      if ((*charIT).type != changeType)
    210217      {
     
    217224      for (unsigned int i = inputLenght; i < addLength; i++)
    218225        if (addString[i] != (*charIT).name[i])
    219         {
    220226          addLength = i;
    221           //       break;
    222         }
    223227    }
    224228    PRINT(0)("\n");
Note: See TracChangeset for help on using the changeset viewer.