Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6004


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.

Location:
code/branches/console/src
Files:
10 edited

Legend:

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

    r5994 r6004  
    6767#include "LuaState.h"
    6868#include "ScopedSingletonManager.h"
    69 #include "Shell.h"
    7069#include "TclBind.h"
    7170#include "TclThreadManager.h"
     
    233232        this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
    234233
    235         // create a shell
    236         this->shell_.reset(new Shell());
    237234        // create persistent io console
    238235        this->ioConsole_.reset(new IOConsole());
  • code/branches/console/src/libraries/core/Core.h

    r5994 r6004  
    9494            scoped_ptr<TclBind>           tclBind_;
    9595            scoped_ptr<TclThreadManager>  tclThreadManager_;
    96             scoped_ptr<Shell>             shell_;
    9796            scoped_ptr<IOConsole>         ioConsole_;
    9897            // graphical
  • code/branches/console/src/libraries/core/IOConsole.cc

    r5998 r6004  
    5252    const std::string promptString_g = "orxonox>";
    5353
    54 #if 1//def ORXONOX_PLATFORM_UNIX
     54#ifdef ORXONOX_PLATFORM_UNIX
    5555
    5656    termios* IOConsole::originalTerminalSettings_;
     
    6767
    6868    IOConsole::IOConsole()
    69         : shell_(Shell::getInstance())
    70         , buffer_(Shell::getInstance().getInputBuffer())
     69        : shell_(new Shell("IOConsole", false))
     70        , buffer_(shell_->getInputBuffer())
     71        , originalTerminalSettings_(new termios())
    7172        , bStatusPrinted_(false)
    7273    {
    73         this->originalTerminalSettings_ = new termios;
    7474        this->setTerminalMode();
    75         this->shell_.registerListener(this);
    76 
     75        this->shell_->registerListener(this);
    7776
    7877        // Manually set the widths of the individual status lines
    79         this->statusLineWidths_.push_back(20);
     78        this->statusLineWidths_.push_back(6);
     79        this->statusLineMaxWidth_ = 6;
    8080    }
    8181
     
    8686        resetTerminalMode();
    8787        delete this->originalTerminalSettings_;
     88        this->shell_->destroy();
    8889    }
    8990
     
    189190            this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0));
    190191
    191         // Print input line
     192        // Clear screen below the last output line by first moving the cursor to the beginning of the first status line
     193        std::cout << "\033[" << (this->bStatusPrinted_ ? this->statusLineWidths_.size() : 0) << "F\033[J";
     194        this->printStatusLines();
    192195        this->printInputLine();
    193196    }
     
    233236        // Set cursor to the beginning of the line and erase the line
    234237        std::cout << "\033[1G\033[K";
    235         // Print status line
    236         //std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
    237238        // Indicate a command prompt
    238239        std::cout << promptString_g;
     
    240241        std::cout << "\033[s";
    241242        // Print command line buffer
    242         std::cout << this->shell_.getInput();
     243        std::cout << this->shell_->getInput();
    243244        // Restore cursor position and move it to the right
    244245        std::cout << "\033[u";
     
    252253        if (!this->statusLineWidths_.empty())
    253254        {
    254             if (this->bStatusPrinted_)
    255             {
    256                 // Erase the status lines first (completely, including new lines!)
    257 
    258             }
    259255            // Check terminal size
    260             /*
    261256            int x, y;
    262             if (this->getTerminalSize(&x, &y) && (x < statusTextWidth_g || y < (2 + statusTextHeight_g)))
     257            if (this->getTerminalSize(&x, &y) && (x < (int)this->statusLineMaxWidth_ || y < (int)(this->minOutputLines_ + this->statusLineWidths_.size())))
    263258            {
    264259                this->bStatusPrinted_ = false;
    265260                return;
    266261            }
    267             */
     262            std::cout << "Status" << std::endl;
     263            std::cout.flush();
     264            this->bStatusPrinted_ = true;
    268265        }
    269266    }
     
    307304
    308305    IOConsole::IOConsole()
    309         : shell_(Shell::getInstance())
    310         , buffer_(Shell::getInstance().getInputBuffer())
     306        : shell_(new Shell("IOConsole", false))
     307        , buffer_(shell_->getInputBuffer())
    311308    {
    312309        this->setTerminalMode();
     
    329326    }
    330327
    331     void IOConsole::print(const std::string& text)
     328    void IOConsole::printLogText(const std::string& text)
    332329    {
    333330    }
     
    360357    {
    361358        // Save cursor position and move it to the beginning of the first output line
    362         std::cout << "\033[s\033[" << (1 + 0/*statusTextHeight_g*/) << "F";
     359        std::cout << "\033[s\033[" << (1 + this->statusLineWidths_.size()) << "F";
    363360        // Erase the line
    364361        std::cout << "\033[K";
    365362        // Reprint the last output line
    366         this->printLogText(*(this->shell_.getNewestLineIterator()));
     363        this->printLogText(*(this->shell_->getNewestLineIterator()));
    367364        // Restore cursor
    368365        std::cout << "\033[u";
     
    376373    void IOConsole::lineAdded()
    377374    {
    378         // Save cursor and move it to the beginning of the first status line
    379         std::cout << "\033[s\033[" << 0/*statusTextHeight_g*/ << "F";
    380         // Create a new line and move cursor to the beginning of it (one cell up)
    381         std::cout << std::endl << "\033[1F";
     375        // Move cursor to the beginning of the first status line and erase screen from there
     376        std::cout << "\033[" << this->statusLineWidths_.size() << "F\033[J";
    382377        // Print the new output line
    383         this->printLogText(*(this->shell_.getNewestLineIterator()));
    384         // Restore cursor (for horizontal position) and move it down again (just in case the lines were shifted)
    385         std::cout << "\033[u\033[" << (1 + 0/*statusTextHeight_g*/) << "B";
    386         std::cout.flush();
     378        this->printLogText(*(this->shell_->getNewestLineIterator()));
     379        std::cout << std::endl;
     380        this->printStatusLines();
     381        this->printInputLine();
    387382    }
    388383
     
    414409        std::cout << "\033[1G";
    415410        // Print command so the user knows what he has typed
    416         std::cout << promptString_g << this->shell_.getInput() << std::endl;
     411        std::cout << promptString_g << this->shell_->getInput() << std::endl;
    417412        this->printInputLine();
    418413    }
  • code/branches/console/src/libraries/core/IOConsole.h

    r5998 r6004  
    7070        void executed();
    7171        void exit();
    72         Shell&                  shell_;
     72        Shell*                  shell_;
    7373        InputBuffer*            buffer_;
    7474        static termios*         originalTerminalSettings_;
     
    7676        bool                    bStatusPrinted_;
    7777        std::vector<unsigned>   statusLineWidths_;
     78        unsigned int            statusLineMaxWidth_;
     79        static const unsigned   minOutputLines_ = 3;
    7880
    7981        static IOConsole* singletonPtr_s;
  • 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>();
  • code/branches/console/src/libraries/core/Shell.h

    r5994 r6004  
    3232#include "CorePrereqs.h"
    3333
    34 #include <cassert>
    3534#include <list>
    3635#include <sstream>
     
    3938
    4039#include "util/OutputHandler.h"
    41 #include "input/InputBuffer.h"
    4240#include "OrxonoxClass.h"
    4341#include "ConfigFileManager.h"
     42#include "input/InputBuffer.h"
    4443
    4544namespace orxonox
     
    6261    };
    6362
    64     class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputListener
     63    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
    6564    {
    66         friend class Singleton<Shell>;
    6765        public:
    68             Shell();
     66            Shell(const std::string& consoleName, bool bScrollable);
    6967            virtual ~Shell();
    70 
    71             static void clearShell();
    72             static void history();
    7368
    7469            void setConfigValues();
     
    10095
    10196            inline unsigned int getNumLines() const
    102                 { return this->lines_.size(); }
     97                { return this->outputLines_.size(); }
    10398            inline unsigned int getScrollPosition() const
    10499                { return this->scrollPosition_; }
     
    115110            std::string getFromHistory() const;
    116111
    117             virtual void outputChanged();
     112            virtual void outputChanged(int level);
    118113
    119114            void inputChanged();
     
    146141            std::stringstream outputBuffer_;
    147142            bool finishedLastLine_;
    148             std::list<std::string> lines_;
     143            std::list<std::string> outputLines_;
    149144            std::list<std::string>::const_iterator scrollIterator_;
    150145            unsigned int scrollPosition_;
     146            unsigned int historyPosition_;
     147            bool bAddOutputLevel_;
     148            ConfigFileType commandHistoryConfigFileType_;
     149            const std::string consoleName_;
     150            const bool bScrollable_;
     151
     152            // Config values
     153            unsigned int maxHistoryLength_;
     154            unsigned int historyOffset_;
    151155            std::vector<std::string> commandHistory_;
    152             unsigned int maxHistoryLength_;
    153             unsigned int historyPosition_;
    154             unsigned int historyOffset_;
    155             bool bAddOutputLevel_;
    156156            int softDebugLevel_;
    157 
    158             ConfigFileType commandHistoryConfigFileType_;
    159 
    160             static Shell* singletonPtr_s;
    161157    };
    162158}
  • code/branches/console/src/libraries/util/OutputHandler.cc

    r6000 r6004  
    9393            this->outputStream_ = &this->logFile_;
    9494            // Use default level until we get the configValue from the Core
    95             outputHandler.setSoftDebugLevel(this->getOutputListenerName(), OutputLevel::Debug);
     95            this->setSoftDebugLevel(OutputLevel::Debug);
    9696            outputHandler.registerOutputListener(this);
    9797        }
     
    152152            this->outputStream_ = &this->buffer_;
    153153            // We capture as much input as the listener with the highest level
    154             outputHandler.setSoftDebugLevel(this->getOutputListenerName(), OutputHandler::getSoftDebugLevel());
     154            this->setSoftDebugLevel(OutputHandler::getSoftDebugLevel());
    155155            outputHandler.registerOutputListener(this);
    156156        }
    157157
    158158        //! Pushed the just written output to the internal array
    159         void outputChanged()
     159        void outputChanged(int level)
    160160        {
    161161            // Read ostringstream and store it
    162             this->output_.push_back(std::make_pair(OutputHandler::getInstance().getOutputLevel(), this->buffer_.str()));
     162            this->output_.push_back(std::make_pair(level, this->buffer_.str()));
    163163            // Clear content and flags
    164164            this->buffer_.str(std::string());
     
    210210        }
    211211        this->listeners_.push_back(listener);
     212        // Update global soft debug level
     213        this->setSoftDebugLevel(listener->getOutputListenerName(), listener->getSoftDebugLevel());
    212214    }
    213215
  • code/branches/console/src/libraries/util/OutputHandler.h

    r5996 r6004  
    142142            //! Returns the soft debug level for a device by its name   @return The level or -1 if the listener was not found
    143143            int  getSoftDebugLevel(const std::string& name) const;
    144             //! Sets the soft debug level for a listener by its name
     144            //! Sets the soft debug level for a listener by its name   @remarks Only works for registered listeners!
    145145            void setSoftDebugLevel(const std::string& name, int level);
    146146
     
    231231            : outputStream_(NULL)
    232232            , name_(name)
     233            , softDebugLevel_(OutputLevel::Info)
    233234        {}
    234235        virtual ~OutputListener() {}
    235236
    236237        //! Gets called whenever output is put into the stream
    237         virtual void outputChanged() {}
     238        virtual void outputChanged(int level) {}
    238239        //! Returns the name of this output listener
    239240        const std::string& getOutputListenerName() const { return this->name_; }
     241        //! Returns the soft debug level of the listener
     242        int getSoftDebugLevel() const { return this->softDebugLevel_; }
     243        //! Sets the soft debug level of the listener
     244        void setSoftDebugLevel(int level)
     245        {
     246            this->softDebugLevel_ = level;
     247            OutputHandler::getInstance().setSoftDebugLevel(this->name_, level);
     248        }
    240249
    241250    protected:
     
    257266                stream << output;
    258267                stream.flush();
    259                 (*it)->outputChanged();
     268                (*it)->outputChanged(this->outputLevel_);
    260269            }
    261270        }
  • code/branches/console/src/orxonox/overlays/InGameConsole.cc

    r5992 r6004  
    6868    */
    6969    InGameConsole::InGameConsole()
    70         : shell_(Shell::getInstance())
     70        : shell_(new Shell("InGameConsole", true))
    7171        , consoleOverlay_(0)
    7272        , consoleOverlayContainer_(0)
     
    100100        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
    101101        InputManager::getInstance().destroyState("console");
     102
     103        // destroy the underlaying shell
     104        this->shell_->destroy();
    102105
    103106        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     
    175178        // create the corresponding input state
    176179        inputState_ = InputManager::getInstance().createInputState("console", false, false, InputStatePriority::Console);
    177         inputState_->setKeyHandler(this->shell_.getInputBuffer());
     180        inputState_->setKeyHandler(this->shell_->getInputBuffer());
    178181        bHidesAllInputChanged();
    179182
     
    253256        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
    254257
    255         this->shell_.addOutputLevel(true);
     258        this->shell_->addOutputLevel(true);
    256259
    257260        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     
    267270    void InGameConsole::linesChanged()
    268271    {
    269         std::list<std::string>::const_iterator it = this->shell_.getNewestLineIterator();
     272        std::list<std::string>::const_iterator it = this->shell_->getNewestLineIterator();
    270273        int max = 0;
    271274        for (int i = 1; i < LINES; ++i)
    272275        {
    273             if (it != this->shell_.getEndIterator())
     276            if (it != this->shell_->getEndIterator())
    274277            {
    275278                ++it;
     
    296299    {
    297300        if (LINES > 1)
    298             this->print(*this->shell_.getNewestLineIterator(), 1);
     301            this->print(*this->shell_->getNewestLineIterator(), 1);
    299302    }
    300303
     
    315318    {
    316319        if (LINES > 0)
    317             this->print(this->shell_.getInput(), 0);
    318 
    319         if (this->shell_.getInput() == "" || this->shell_.getInput().size() == 0)
     320            this->print(this->shell_->getInput(), 0);
     321
     322        if (this->shell_->getInput() == "" || this->shell_->getInput().size() == 0)
    320323            this->inputWindowStart_ = 0;
    321324    }
     
    326329    void InGameConsole::cursorChanged()
    327330    {
    328         unsigned int pos = this->shell_.getCursorPosition() - inputWindowStart_;
     331        unsigned int pos = this->shell_->getCursorPosition() - inputWindowStart_;
    329332        if (pos > maxCharsPerLine_)
    330333            pos = maxCharsPerLine_;
     
    483486                if (output.size() > this->maxCharsPerLine_)
    484487                {
    485                     if (this->shell_.getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
    486                         this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition();
    487                     else if (this->shell_.getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
    488                         this->inputWindowStart_ = this->shell_.getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
     488                    if (this->shell_->getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
     489                        this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition();
     490                    else if (this->shell_->getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
     491                        this->inputWindowStart_ = this->shell_->getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
    489492
    490493                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
     
    507510            this->bActive_ = true;
    508511            InputManager::getInstance().enterState("console");
    509             this->shell_.registerListener(this);
     512            this->shell_->registerListener(this);
    510513
    511514            this->windowResized(this->windowW_, this->windowH_);
     
    529532            this->bActive_ = false;
    530533            InputManager::getInstance().leaveState("console");
    531             this->shell_.unregisterListener(this);
     534            this->shell_->unregisterListener(this);
    532535
    533536            // scroll up
  • code/branches/console/src/orxonox/overlays/InGameConsole.h

    r5969 r6004  
    8181
    8282    private: // variables
    83         Shell& shell_;
     83        Shell* shell_;
    8484        bool bActive_;
    8585        int windowW_;
Note: See TracChangeset for help on using the changeset viewer.