Index: trunk/src/lib/shell/shell.cc
===================================================================
--- trunk/src/lib/shell/shell.cc	(revision 5177)
+++ trunk/src/lib/shell/shell.cc	(revision 5179)
@@ -19,4 +19,5 @@
 #include "shell_command.h"
 #include "shell_buffer.h"
+#include "shell_input.h"
 
 
@@ -56,12 +57,7 @@
 
   // INPUT LINE
+  this->shellInput = new ShellInput;
   this->delayed = 0;
-  this->setRepeatDelay(.3, .05);
-  this->pressedKey = SDLK_FIRST;
-
-  this->inputLineText = NULL;
-  this->inputLine = new char[1];
-  this->inputLine[0] = '\0';
-  this->inputHistory = new tList<char>;
+  this->shellInput->setRepeatDelay(.3, .05);
   //this->commandList = new tList<ShellCommand>;
 
@@ -89,6 +85,4 @@
 
   // delete the inputLine
-  delete this->inputLineText;
-  delete this->inputLine;
 
   Shell::singletonRef = NULL;
@@ -155,12 +149,10 @@
 void Shell::rebuildText()
 {
-  if (this->inputLineText == NULL)
-    delete this->inputLineText;
-  this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
-  this->inputLineText->setColor(1, 0, 0);
-  this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
-  this->inputLineText->setText(NULL);
-  this->inputLineText->setParent2D(this);
-  this->inputLineText->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
+  this->shellInput->setFont("fonts/Aniron_Bold.ttf", this->textSize);
+  this->shellInput->setColor(1, 0, 0);
+  this->shellInput->setAlignment(TEXT_ALIGN_LEFT);
+  this->shellInput->setText(NULL);
+  this->shellInput->setParent2D(this);
+  this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
 
   this->setBufferDisplaySize(this->bufferDisplaySize);
@@ -240,86 +232,4 @@
 
 /**
- * deletes the InputLine
- */
-void Shell::flushInputLine()
-{
-  if (likely(this->inputLine != NULL))
-  {
-    delete[] this->inputLine;
-  }
-  this->inputLine = new char[1];
-  *this->inputLine = '\0';
-  this->inputLineText->setText(this->inputLine, true);
-}
-
-/**
- * adds one character to the inputLine
- * @param character the character to add to the inputLine
- */
-void Shell::addCharacter(char character)
-{
-  char* addCharLine = new char[strlen(inputLine)+2];
-
-  sprintf(addCharLine, "%s%c", this->inputLine, character);
-  delete this->inputLine;
-  this->inputLine = addCharLine;
-  this->inputLineText->setText(inputLine, true);
-}
-
-/**
- * adds multiple Characters to thr inputLine
- * @param characters a \\0 terminated char-array to add to the InputLine
- */
-void Shell::addCharacters(const char* characters)
-{
-  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
-
-  sprintf(addCharLine, "%s%s", this->inputLine, characters);
-  delete this->inputLine;
-  this->inputLine = addCharLine;
-  this->inputLineText->setText(inputLine, true);
-}
-
-/**
- * removes characterCount characters from the InputLine
- * @param characterCount the count of Characters to remove from the input Line
- */
-void Shell::removeCharacters(unsigned int characterCount)
-{
-  if (strlen(this->inputLine) == 0)
-    return;
-
-  if (characterCount > strlen(this->inputLine))
-    characterCount = strlen(this->inputLine);
-
-  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
-
-  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
-  removeCharLine[strlen(inputLine)-characterCount] = '\0';
-  delete this->inputLine;
-  this->inputLine = removeCharLine;
-  this->inputLineText->setText(inputLine, true);
-}
-
-/**
- * executes the command stored in the inputLine
- * @return true if the command was commited successfully, false otherwise
- */
-bool Shell::executeCommand()
-{
-  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
-
-  char* newCommand = new char[strlen(this->inputLine)+1];
-  strcpy(newCommand, this->inputLine);
-  this->inputHistory->add(newCommand);
-
-  ShellCommandBase::execute(this->inputLine);
-
-  this->flushInputLine();
-
-  return false;
-}
-
-/**
  * clears the Shell (empties all buffers)
  */
@@ -330,15 +240,5 @@
 }
 
-/**
- * sets the Repeate-delay and rate
- * @param repeatDelay the Delay it takes, to repeate a key
- * @param repeatRate the rate to repeate a pressed key
- */
-void Shell::setRepeatDelay(float repeatDelay, float repeatRate)
-{
-  this->repeatDelay = repeatDelay;
-  this->repeatRate = repeatRate;
-
-}
+
 
 /**
@@ -363,13 +263,13 @@
       this->debug();
     else if (event.type == SDLK_TAB)
-      this->autoComplete();
+      ;//this->autoComplete();
     else if (event.type == SDLK_BACKSPACE)
     {
       this->delayed = this->repeatDelay;
       this->pressedKey = SDLK_BACKSPACE;
-      this->removeCharacters(1);
+      this->shellInput->removeCharacters(1);
     }
     else if (event.type == SDLK_RETURN)
-      this->executeCommand();
+      this->shellInput->executeCommand();
     /*
     else if (event.type == SDLK_UP)
@@ -397,10 +297,10 @@
       {
         this->pressedKey = event.type-32;
-        this->addCharacter(event.type-32);
+        this->shellInput->addCharacter(event.type-32);
       }
       else
       {
         this->pressedKey = event.type;
-        this->addCharacter(event.type);
+        this->shellInput->addCharacter(event.type);
       }
     }
@@ -428,7 +328,7 @@
     this->delayed = this->repeatRate;
     if (this->pressedKey == SDLK_BACKSPACE)
-      this->removeCharacters(1);
+      this->shellInput->removeCharacters(1);
     else if (pressedKey < 127)
-      this->addCharacter(this->pressedKey);
+      this->shellInput->addCharacter(this->pressedKey);
   }
 }
@@ -463,218 +363,4 @@
 
   glEnd();
-}
-
-
-/**
- * autocompletes the Shell's inputLine
- * @returns true, if a result was found, false otherwise
- *
- * @todo implement it!!
- */
-bool Shell::autoComplete()
-{
-  //PRINTF(3)("AutoCompletion not implemented yet\n");
-
-  char* completionLine = new char[strlen(inputLine)+1];
-  strcpy(completionLine, this->inputLine);
-
-  char* commandBegin = strrchr(completionLine, ' ');
-  if (commandBegin == NULL)
-    commandBegin = completionLine;
-  else
-  {
-    if(commandBegin >= completionLine + strlen(completionLine))
-      commandBegin = completionLine + strlen(completionLine);
-    else
-      commandBegin++;
-  }
-
-  char* objectStart;
-  if (objectStart = strstr(commandBegin, "::"))
-  {
-    char* classIdentity = new char[objectStart - commandBegin +1];
-    strncpy(classIdentity, commandBegin, objectStart - commandBegin);
-    classIdentity[objectStart - commandBegin] = '\0';
-    this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
-    delete[] classIdentity;
-  }
-  else
-    this->classComplete(commandBegin);
-
-  delete[] completionLine;
-}
-
-/**
- * autocompletes a className
- * @param classBegin the Beginning of a String to autoComplete
- * @return true on success, false otherwise
- */
-bool Shell::classComplete(const char* classBegin)
-{
-  if (unlikely(classBegin == NULL))
-    return false;
-  const tList<const char>* clList = ClassList::getClassList();
-  if (clList != NULL)
-  {
-    const tList<const char>* classList = this->createCompleteList(clList, classBegin);
-    if (classList != NULL)
-      this->generalComplete(classList, classBegin, "%s::", "::");
-    else
-      return false;
-  }
-  else
-    return false;
-  return true;
-}
-
-/**
- * autocompletes an ObjectName
- * @param objectBegin the beginning string of a Object
- * @param classID the ID of the Class to search for.
- * @return true on success, false otherwise
- */
-bool Shell::objectComplete(const char* objectBegin, long classID)
-{
-  printf("%s\n", objectBegin);
-
-  if (unlikely(objectBegin == NULL))
-    return false;
-  tList<BaseObject>* boList = ClassList::getList(classID);
-  if (boList != NULL)
-  {
-    printf("\n", boList->firstElement()->getName());
-    const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
-    if (objectList != NULL)
-      this->generalComplete(objectList, objectBegin, "%s");
-    else
-      return false;
-  }
-  else
-    return false;
-  return true;
-}
-
-/**
- * completes a Function
- * @param functionBegin the beginning of the function String
- */
-bool Shell::functionComplete(const char* functionBegin)
-{
-}
-
-/**
- * completes the inputline on grounds of an inputList
- * @param stringList the List to parse through
- * @param begin the String to search in the inputList, and to extend with it.
- * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
- * @param addBack what should be added at the end of the completion
- * @param addFront what should be added to the front of one finished completion
- * @return true if ok, false otherwise
- */
-bool Shell::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
-{
-  if (stringList->getSize() == 0)
-    return false;
-
-  const char* addString = stringList->firstElement();
-  unsigned int addLength = 0;
-  unsigned int inputLenght = strlen(begin);
-
-  if (addString != NULL)
-    addLength = strlen(addString);
-  tIterator<const char>* charIterator = stringList->getIterator();
-  const char* charElem = charIterator->firstElement();
-  while (charElem != NULL)
-  {
-    PRINTF(0)(displayAs, charElem);
-    for (unsigned int i = inputLenght; i < addLength; i++)
-      if (addString[i] != charElem[i])
-    {
-      addLength = i;
-      break;
-    }
-    charElem = charIterator->nextElement();
-  }
-  delete charIterator;
-
-  if (addLength >= inputLenght)
-  {
-    char* adder = new char[addLength+1];
-    strncpy(adder, addString, addLength);
-    adder[addLength] = '\0';
-    this->removeCharacters(inputLenght);
-    this->addCharacters(adder);
-    if (addBack != NULL && stringList->getSize() == 1)
-      this->addCharacters("::");
-    delete[] adder;
-  }
-  return true;
-}
-
-/**
- * searches for classes, which beginn with classNameBegin
- * @param inputList the List to parse through
- * @param classNameBegin the beginning string
- * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
- * !! The strings MUST NOT be deleted !!
- */
-const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
-{
-  if (inputList == NULL || classNameBegin == NULL)
-    return NULL;
-  unsigned int searchLength = strlen(classNameBegin);
-  if (this->completionList != NULL)
-    delete this->completionList;
-  this->completionList = new tList<const char>;
-
-//  tList<const char>* classList = ClassList::getClassList();
-
-  tIterator<const char>* iterator = inputList->getIterator();
-  const char* enumString = iterator->firstElement();
-  while (enumString != NULL)
-  {
-    if (strlen(enumString)>searchLength+1 &&
-        !strncasecmp(enumString, classNameBegin, searchLength))
-    {
-      this->completionList->add(enumString);
-    }
-    enumString = iterator->nextElement();
-  }
-  delete iterator;
-
-  return this->completionList;
-}
-
-/**
- * searches for classes, which beginn with classNameBegin
- * @param inputList the List to parse through
- * @param classNameBegin the beginning string
- * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
- * !! The strings MUST NOT be deleted !!
- */
-const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
-{
-  if (inputList == NULL || classNameBegin == NULL)
-    return NULL;
-  unsigned int searchLength = strlen(classNameBegin);
-  if (this->completionList != NULL)
-    delete this->completionList;
-  this->completionList = new tList<const char>;
-
-  tIterator<BaseObject>* iterator = inputList->getIterator();
-  BaseObject* enumBO = iterator->firstElement();
-  while (enumBO != NULL)
-  {
-    if (enumBO->getName() != NULL &&
-        strlen(enumBO->getName())>searchLength+1 &&
-        !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
-    {
-      this->completionList->add(enumBO->getName());
-    }
-    enumBO = iterator->nextElement();
-  }
-  delete iterator;
-
-  return this->completionList;
 }
 
