Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2009, 12:39:51 PM (15 years ago)
Author:
rgrieder
Message:

De-singletonised Shell so that both consoles have their own Shell instance. However they share the history.
Also modified IOConsole to hopefully work with status lines.

File:
1 edited

Legend:

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

    r5994 r6004  
    3434#include "CoreIncludes.h"
    3535#include "ConfigValueIncludes.h"
    36 #include "Core.h"
    3736#include "ConsoleCommand.h"
    3837
    3938namespace orxonox
    4039{
    41     SetConsoleCommand(Shell, clearShell, true);
    42     SetConsoleCommand(Shell, history, true);
    43 
    4440    SetConsoleCommandShortcut(OutputHandler, log);
    4541    SetConsoleCommandShortcut(OutputHandler, error);
     
    4844    SetConsoleCommandShortcut(OutputHandler, debug);
    4945
    50     Shell* Shell::singletonPtr_s = 0;
    51 
    52     Shell::Shell()
    53         : OutputListener("shell")
     46    Shell::Shell(const std::string& consoleName, bool bScrollable)
     47        : inputBuffer_(new InputBuffer())
     48        , OutputListener(consoleName)
     49        , consoleName_(consoleName)
     50        , bScrollable_(bScrollable)
    5451    {
    5552        RegisterRootObject(Shell);
     
    6360
    6461        this->clearLines();
    65 
    66         this->inputBuffer_ = new InputBuffer();
    6762        this->configureInputBuffer();
    6863
     
    7974        for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
    8075            it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
    81             this->addLine(it->second, it->first);
     76        {
     77            if (it->first <= this->getSoftDebugLevel())
     78            {
     79                this->outputBuffer_ << it->second;
     80                this->outputChanged(it->first);
     81            }
     82        }
    8283
    8384        // Register the shell as output listener
     
    9394    void Shell::setConfigValues()
    9495    {
    95         SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100)
     96        SetConfigValue(maxHistoryLength_, 100)
    9697            .callback(this, &Shell::commandHistoryLengthChanged);
    97         SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0)
     98        SetConfigValue(historyOffset_, 0)
    9899            .callback(this, &Shell::commandHistoryOffsetChanged);
    99100        SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>());
     
    104105        const unsigned int defaultLevel = 3;
    105106#endif
    106         SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevelShell", "OutputHandler", defaultLevel)
     107        SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevel" + this->consoleName_, "OutputHandler", defaultLevel)
    107108            .description("The maximal level of debug output shown in the Shell");
    108         OutputHandler::getInstance().setSoftDebugLevel("shell", this->softDebugLevel_);
     109        this->setSoftDebugLevel(this->softDebugLevel_);
    109110    }
    110111
     
    149150    }
    150151
    151     void Shell::clearShell()
    152     {
    153         Shell::getInstance().clearLines();
    154     }
    155 
     152    /*
    156153    void Shell::history()
    157154    {
     
    163160            instance.addLine(instance.commandHistory_[i], -1);
    164161    }
     162    */
    165163
    166164    void Shell::registerListener(ShellListener* listener)
     
    195193    {
    196194        if (level <= this->softDebugLevel_)
    197             this->lines_.push_front(line);
     195            this->outputLines_.push_front(line);
    198196        this->updateListeners<&ShellListener::lineAdded>();
    199197    }
     
    201199    void Shell::clearLines()
    202200    {
    203         this->lines_.clear();
    204         this->scrollIterator_ = this->lines_.begin();
     201        this->outputLines_.clear();
     202        this->scrollIterator_ = this->outputLines_.begin();
    205203
    206204        this->scrollPosition_ = 0;
     
    215213            return this->scrollIterator_;
    216214        else
    217             return this->lines_.begin();
     215            return this->outputLines_.begin();
    218216    }
    219217
    220218    std::list<std::string>::const_iterator Shell::getEndIterator() const
    221219    {
    222         return this->lines_.end();
     220        return this->outputLines_.end();
    223221    }
    224222
     
    239237    }
    240238
    241     void Shell::outputChanged()
    242     {
    243         std::string output;
    244         bool newline;
     239    void Shell::outputChanged(int level)
     240    {
     241        bool newline = false;
    245242        do
    246243        {
     244            std::string output;
    247245            std::getline(this->outputBuffer_, output);
    248246
     
    261259            {
    262260                if (this->bAddOutputLevel_)
    263                     output.insert(0, 1, static_cast<char>(OutputHandler::getInstance().getOutputLevel()));
    264 
    265                 this->lines_.push_front(output);
     261                    output.insert(0, 1, static_cast<char>(level));
     262
     263                this->outputLines_.push_front(output);
    266264
    267265                if (this->scrollPosition_)
    268266                    this->scrollPosition_++;
    269267                else
    270                     this->scrollIterator_ = this->lines_.begin();
     268                    this->scrollIterator_ = this->outputLines_.begin();
    271269
    272270                this->finishedLastLine_ = newline;
     
    279277            else
    280278            {
    281                 (*this->lines_.begin()) += output;
     279                (*this->outputLines_.begin()) += output;
    282280                this->finishedLastLine_ = newline;
    283281                this->updateListeners<&ShellListener::onlyLastLineChanged>();
     
    413411    void Shell::scroll_up()
    414412    {
    415         if (this->scrollIterator_ != this->lines_.end())
     413        if (this->scrollIterator_ != this->outputLines_.end())
    416414        {
    417415            ++this->scrollIterator_;
     
    424422    void Shell::scroll_down()
    425423    {
    426         if (this->scrollIterator_ != this->lines_.begin())
     424        if (this->scrollIterator_ != this->outputLines_.begin())
    427425        {
    428426            --this->scrollIterator_;
     
    443441        this->clear();
    444442        this->scrollPosition_ = 0;
    445         this->scrollIterator_ = this->lines_.begin();
     443        this->scrollIterator_ = this->outputLines_.begin();
    446444
    447445        this->updateListeners<&ShellListener::exit>();
Note: See TracChangeset for help on using the changeset viewer.