Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 19, 2008, 2:58:22 PM (16 years ago)
Author:
landauf
Message:

Added a command-history to the console. you can scroll through all previously entered commands by pressing [up] key.
The history is stored in orxonox.ini in the section [Shell]. You can configure the maximal amount of stored commands (default: 100).
This allows you to use the history after orxonox was restarted.
The history uses a cyclic vector (with the configured size), meaning the newest command will overwrite the oldest entry (if the maximal size was reached).

additionally I fixed some bugs in ConfigValueContainer and added a mod-function to Math.h, that does basically the same as %, but without returning a negative value in case of a negative input.

-1 % 10 = -1
-11 % 10 = -1

mod(-1, 10) = 9
mod(-11, 10) = 9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/Shell.cc

    r1322 r1324  
    8080        SetConfigValue(maxHistoryLength_, 100);
    8181        SetConfigValue(historyOffset_, 0);
    82         SetConfigValueVector(commandHistory_, std::vector<std::string>());
    83 
    84 std::cout << "gaga1: " << this->commandHistory_[this->historyOffset_] << std::endl;
     82        SetConfigValueVector(commandHistory_, std::vector<std::string>(1, ""));
    8583
    8684        if (this->historyOffset_ >= this->maxHistoryLength_)
     
    9391            ModifyConfigValue(commandHistory_, remove, index);
    9492        }
    95 
    96 std::cout << "gaga2: " << this->commandHistory_[this->historyOffset_] << std::endl;
    9793    }
    9894
     
    163159    void Shell::addToHistory(const std::string& command)
    164160    {
    165 std::cout << "command: " << command << std::endl;
    166 std::cout << "offset: " << this->historyOffset_ << std::endl;
    167161        ModifyConfigValue(commandHistory_, set, this->historyOffset_, command);
    168 //        this->commandHistory_[this->historyOffset_] = command;
    169162        this->historyPosition_ = 0;
    170 std::cout << "gaga3: " << this->commandHistory_[this->historyOffset_] << std::endl;
    171163        ModifyConfigValue(historyOffset_, set, (this->historyOffset_ + 1) % this->maxHistoryLength_);
    172 std::cout << "offset new: " << this->historyOffset_ << std::endl;
    173164    }
    174165
    175166    std::string Shell::getFromHistory() const
    176167    {
    177         return this->commandHistory_[(this->historyOffset_ - this->historyPosition_) % this->maxHistoryLength_];
     168        unsigned int index = mod(((int)this->historyOffset_) - ((int)this->historyPosition_), this->maxHistoryLength_);
     169        if (index < this->commandHistory_.size() && this->historyPosition_ != 0)
     170            return this->commandHistory_[index];
     171        else
     172            return "";
    178173    }
    179174
     
    219214    void Shell::execute()
    220215    {
    221 //        this->addToHistory(this->inputBuffer_.get());
     216        this->addToHistory(this->inputBuffer_.get());
    222217        this->addLine(this->inputBuffer_.get(), 0);
    223218
     
    252247    {
    253248        this->inputBuffer_.clear();
     249        this->historyPosition_ = 0;
    254250        SHELL_UPDATE_LISTENERS(inputChanged);
    255251        SHELL_UPDATE_LISTENERS(cursorChanged);
     
    282278    void Shell::history_up()
    283279    {
    284         if (this->historyPosition_ < (this->commandHistory_.size() - 1))
     280        if (this->historyPosition_ < this->commandHistory_.size())
    285281        {
    286282            this->historyPosition_++;
Note: See TracChangeset for help on using the changeset viewer.