Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 13, 2005, 11:23:34 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellInput is now almost perfectly extern.
ShellCompletion taken out.
Working again :)

File:
1 edited

Legend:

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

    r5178 r5179  
    1818#include "shell_input.h"
    1919
     20#include "text_engine.h"
     21
     22#include "shell_command.h"
     23#include "debug.h"
     24#include "list.h"
     25#include "compiler.h"
     26#include "stdlibincl.h"
     27
    2028using namespace std;
    2129
     
    2735ShellInput::ShellInput ()
    2836{
     37  this->pressedKey = SDLK_FIRST;
    2938
     39  this->inputLine = new char[1];
     40  this->inputLine[0] = '\0';
     41  this->inputHistory = new tList<char>;
    3042}
    3143
     
    3749  // delete what has to be deleted here
    3850}
     51
     52/**
     53 * sets the Repeate-delay and rate
     54 * @param repeatDelay the Delay it takes, to repeate a key
     55 * @param repeatRate the rate to repeate a pressed key
     56 */
     57void ShellInput::setRepeatDelay(float repeatDelay, float repeatRate)
     58{
     59  this->repeatDelay = repeatDelay;
     60  this->repeatRate = repeatRate;
     61
     62}
     63
     64/**
     65 * deletes the InputLine
     66 */
     67void ShellInput::flush()
     68{
     69  if (likely(this->inputLine != NULL))
     70  {
     71    delete[] this->inputLine;
     72  }
     73  this->inputLine = new char[1];
     74  *this->inputLine = '\0';
     75  this->setText(this->inputLine, true);
     76}
     77
     78/**
     79 * adds one character to the inputLine
     80 * @param character the character to add to the inputLine
     81 */
     82void ShellInput::addCharacter(char character)
     83{
     84  char* addCharLine = new char[strlen(inputLine)+2];
     85
     86  sprintf(addCharLine, "%s%c", this->inputLine, character);
     87  delete this->inputLine;
     88  this->inputLine = addCharLine;
     89  this->setText(inputLine, true);
     90}
     91
     92/**
     93 * adds multiple Characters to thr inputLine
     94 * @param characters a \\0 terminated char-array to add to the InputLine
     95 */
     96void ShellInput::addCharacters(const char* characters)
     97{
     98  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
     99
     100  sprintf(addCharLine, "%s%s", this->inputLine, characters);
     101  delete this->inputLine;
     102  this->inputLine = addCharLine;
     103  this->setText(inputLine, true);
     104}
     105
     106/**
     107 * removes characterCount characters from the InputLine
     108 * @param characterCount the count of Characters to remove from the input Line
     109 */
     110void ShellInput::removeCharacters(unsigned int characterCount)
     111{
     112  if (strlen(this->inputLine) == 0)
     113    return;
     114
     115  if (characterCount > strlen(this->inputLine))
     116    characterCount = strlen(this->inputLine);
     117
     118  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
     119
     120  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
     121  removeCharLine[strlen(inputLine)-characterCount] = '\0';
     122  delete this->inputLine;
     123  this->inputLine = removeCharLine;
     124  this->setText(inputLine, true);
     125}
     126
     127/**
     128 * executes the command stored in the inputLine
     129 * @return true if the command was commited successfully, false otherwise
     130 */
     131bool ShellInput::executeCommand()
     132{
     133  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
     134
     135  char* newCommand = new char[strlen(this->inputLine)+1];
     136  strcpy(newCommand, this->inputLine);
     137  this->inputHistory->add(newCommand);
     138
     139  ShellCommandBase::execute(this->inputLine);
     140
     141  this->flush();
     142
     143  return false;
     144}
     145
Note: See TracChangeset for help on using the changeset viewer.