Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2009, 2:47:14 PM (15 years ago)
Author:
rgrieder
Message:

Changed Output concept a little bit to allow for more general use.
Every output (log) target has to be implemented as OutputListener. There is already a LogFileWriter and a MemoryLogWriter (stores ALL the log in a vector and provides iterators).
The OutputListener has a unique and constant name, a stream pointer and a soft debug level (that can only be changed via OutputHandler::setSoftDebugLevel(name, level)).
This concept doesn't require the OutputBuffer anymore, so I deleted it.

The adjustments in the Shell are just preliminary for this commit.

File:
1 edited

Legend:

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

    r5986 r5994  
    5151
    5252    Shell::Shell()
    53     {
    54         int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
    55         Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
    56 
     53        : OutputListener("shell")
     54    {
    5755        RegisterRootObject(Shell);
    5856
     
    6967        this->configureInputBuffer();
    7068
    71         this->outputBuffer_.registerListener(this);
    72         OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);
    73 
    7469        // Get a config file for the command history
    7570        this->commandHistoryConfigFileType_ = ConfigFileManager::getInstance().getNewConfigFileType();
    7671        ConfigFileManager::getInstance().setFilename(this->commandHistoryConfigFileType_, "commandHistory.ini");
    7772
     73        // Use a stringstream object to buffer the output and get it line by line in update()
     74        this->outputStream_ = &this->outputBuffer_;
     75
    7876        this->setConfigValues();
    7977
    80         Core::setSoftDebugLevel(OutputHandler::LD_Shell, level);
     78        // Get the previous output and add it to the Shell
     79        for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
     80            it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
     81            this->addLine(it->second, it->first);
     82
     83        // Register the shell as output listener
     84        OutputHandler::getInstance().registerOutputListener(this);
    8185    }
    8286
    8387    Shell::~Shell()
    8488    {
    85         OutputHandler::getOutStream().setOutputBuffer(0);
    86         if (this->inputBuffer_)
    87             this->inputBuffer_->destroy();
     89        OutputHandler::getInstance().unregisterOutputListener(this);
     90        this->inputBuffer_->destroy();
    8891    }
    8992
    9093    void Shell::setConfigValues()
    9194    {
    92         SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, 100)
     95        SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100)
    9396            .callback(this, &Shell::commandHistoryLengthChanged);
    94         SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, 0)
     97        SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0)
    9598            .callback(this, &Shell::commandHistoryOffsetChanged);
    9699        SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>());
     100
     101#ifdef ORXONOX_RELEASE
     102        const unsigned int defaultLevel = 1;
     103#else
     104        const unsigned int defaultLevel = 3;
     105#endif
     106        SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevelShell", "OutputHandler", defaultLevel)
     107            .description("The maximal level of debug output shown in the Shell");
     108        OutputHandler::getInstance().setSoftDebugLevel("shell", this->softDebugLevel_);
    97109    }
    98110
     
    182194    void Shell::addLine(const std::string& line, int level)
    183195    {
    184         int original_level = OutputHandler::getOutStream().getOutputLevel();
    185         OutputHandler::getOutStream().setOutputLevel(level);
    186 
    187         if (!this->finishedLastLine_)
    188             this->outputBuffer_ << std::endl;
    189 
    190         this->outputBuffer_ << line << std::endl;
    191         OutputHandler::getOutStream().setOutputLevel(original_level);
     196        if (level <= this->softDebugLevel_)
     197            this->lines_.push_front(line);
     198        this->updateListeners<&ShellListener::lineAdded>();
    192199    }
    193200
     
    238245        do
    239246        {
    240             newline = this->outputBuffer_.getLine(&output);
     247            std::getline(this->outputBuffer_, output);
     248
     249            bool eof = this->outputBuffer_.eof();
     250            bool fail = this->outputBuffer_.fail();
     251            if (eof)
     252                this->outputBuffer_.flush();
     253            if (eof || fail)
     254                this->outputBuffer_.clear();
     255            newline = (!eof && !fail);
    241256
    242257            if (!newline && output == "")
     
    246261            {
    247262                if (this->bAddOutputLevel_)
    248                     output.insert(0, 1, static_cast<char>(OutputHandler::getOutStream().getOutputLevel()));
    249 
    250                 this->lines_.insert(this->lines_.begin(), output);
     263                    output.insert(0, 1, static_cast<char>(OutputHandler::getInstance().getOutputLevel()));
     264
     265                this->lines_.push_front(output);
    251266
    252267                if (this->scrollPosition_)
     
    365380            return;
    366381        unsigned int cursorPosition = this->getCursorPosition();
    367         std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position
    368         for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)
    369         {
    370             if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //search case insensitive
     382        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position
     383        for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++)
     384        {
     385            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive
    371386            {
    372387                this->historyPosition_ = newPos;
    373388                this->inputBuffer_->set(this->getFromHistory());
    374                 this->setCursorPosition( cursorPosition );
     389                this->setCursorPosition(cursorPosition);
    375390                return;
    376391            }
     
    383398            return;
    384399        unsigned int cursorPosition = this->getCursorPosition();
    385         std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$
    386         for (unsigned int newPos = this->historyPosition_-1; newPos>0; newPos--)
    387         {
    388             if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //sear$
     400        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$
     401        for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--)
     402        {
     403            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$
    389404            {
    390405                this->historyPosition_ = newPos;
    391406                this->inputBuffer_->set(this->getFromHistory());
    392                 this->setCursorPosition( cursorPosition );
     407                this->setCursorPosition(cursorPosition);
    393408                return;
    394409            }
Note: See TracChangeset for help on using the changeset viewer.