/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: ... co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "shell_input.h" #include "text_engine.h" #include "shell_command.h" #include "debug.h" #include "list.h" #include "compiler.h" #include "stdlibincl.h" using namespace std; /** * standard constructor * @todo this constructor is not jet implemented - do it */ ShellInput::ShellInput () { this->pressedKey = SDLK_FIRST; this->inputLine = new char[1]; this->inputLine[0] = '\0'; this->inputHistory = new tList; } /** * standard deconstructor */ ShellInput::~ShellInput () { // delete what has to be deleted here } /** * 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 ShellInput::setRepeatDelay(float repeatDelay, float repeatRate) { this->repeatDelay = repeatDelay; this->repeatRate = repeatRate; } /** * deletes the InputLine */ void ShellInput::flush() { if (likely(this->inputLine != NULL)) { delete[] this->inputLine; } this->inputLine = new char[1]; *this->inputLine = '\0'; this->setText(this->inputLine, true); } /** * adds one character to the inputLine * @param character the character to add to the inputLine */ void ShellInput::addCharacter(char character) { char* addCharLine = new char[strlen(inputLine)+2]; sprintf(addCharLine, "%s%c", this->inputLine, character); delete this->inputLine; this->inputLine = addCharLine; this->setText(inputLine, true); } /** * adds multiple Characters to thr inputLine * @param characters a \\0 terminated char-array to add to the InputLine */ void ShellInput::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->setText(inputLine, true); } /** * removes characterCount characters from the InputLine * @param characterCount the count of Characters to remove from the input Line */ void ShellInput::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->setText(inputLine, true); } /** * executes the command stored in the inputLine * @return true if the command was commited successfully, false otherwise */ bool ShellInput::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->flush(); return false; }