Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 20, 2009, 4:55:40 PM (14 years ago)
Author:
rgrieder
Message:

Merged console branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Shell.h

    r5781 r6105  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    3232#include "CorePrereqs.h"
    3333
    34 #include <cassert>
    3534#include <list>
     35#include <sstream>
    3636#include <string>
    3737#include <vector>
    3838
    39 #include "util/OutputBuffer.h"
    40 #include "input/InputBuffer.h"
     39#include "util/OutputHandler.h"
    4140#include "OrxonoxClass.h"
    4241#include "ConfigFileManager.h"
     42#include "input/InputBuffer.h"
    4343
    4444namespace orxonox
     
    5757            virtual void inputChanged() {}
    5858            virtual void cursorChanged() {}
     59            virtual void executed() {}
    5960            virtual void exit() {}
    6061    };
    6162
    62     class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
     63
     64    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
    6365    {
    64         friend class Singleton<Shell>;
    6566        public:
    66             Shell();
    67             virtual ~Shell();
     67            Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false);
     68            ~Shell();
    6869
    69             static void clearShell();
    70             static void history();
    71 
    72             virtual void setConfigValues();
     70            void setConfigValues();
    7371            void commandHistoryOffsetChanged();
    7472            void commandHistoryLengthChanged();
     
    7977            inline InputBuffer* getInputBuffer()
    8078                { return this->inputBuffer_; }
    81             inline OutputBuffer& getOutputBuffer()
    82                 { return this->outputBuffer_; }
    8379
    8480            void setCursorPosition(unsigned int cursor);
     
    8682                { return this->inputBuffer_->getCursorPosition(); }
    8783
    88             void setInput(const std::string& input);
    89 
    90             inline void clearInput()
    91                 { this->setInput(""); }
    9284            inline std::string getInput() const
    9385                { return this->inputBuffer_->get(); }
     
    9688            std::list<std::string>::const_iterator getEndIterator() const;
    9789
    98             void addLine(const std::string& line, int level = 0);
    99             void clearLines();
     90            void addOutputLine(const std::string& line, int level = 0);
     91            void clearOutput();
    10092
    10193            inline unsigned int getNumLines() const
    102                 { return this->lines_.size(); }
     94                { return this->outputLines_.size(); }
    10395            inline unsigned int getScrollPosition() const
    10496                { return this->scrollPosition_; }
    10597
    106             inline void addOutputLevel(bool bAddOutputLevel)
    107                 { this->bAddOutputLevel_ = bAddOutputLevel; }
     98            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
     99            void setPromptPrefix(const std::string& str);
    108100
    109101        private:
    110102            Shell(const Shell& other);
    111103
     104            void addToHistory(const std::string& command);
     105            std::string getFromHistory() const;
     106            void clearInput();
     107            // OutputListener
     108            void outputChanged(int level);
     109
    112110            void configureInputBuffer();
    113111
    114             void addToHistory(const std::string& command);
    115             std::string getFromHistory() const;
    116 
    117             virtual void outputChanged();
     112            // InputBuffer callbacks
    118113            void inputChanged();
    119114            void execute();
    120             void hintandcomplete();
     115            void hintAndComplete();
    121116            void backspace();
    122             void deletechar();
    123             void clear();
    124             void cursor_right();
    125             void cursor_left();
    126             void cursor_end();
    127             void cursor_home();
    128             void history_up();
    129             void history_down();
    130             void scroll_up();
    131             void scroll_down();
     117            void deleteChar();
     118            void cursorRight();
     119            void cursorLeft();
     120            void cursorEnd();
     121            void cursorHome();
     122            void historyUp();
     123            void historyDown();
     124            void historySearchUp();
     125            void historySearchDown();
     126            void scrollUp();
     127            void scrollDown();
    132128            void exit();
    133129
     130            template <void (ShellListener::*F)()>
     131            void updateListeners()
     132            {
     133                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
     134                    ((*(it++))->*F)();
     135            }
     136
    134137            std::list<ShellListener*> listeners_;
    135             InputBuffer* inputBuffer_;
    136             OutputBuffer outputBuffer_;
    137             bool finishedLastLine_;
    138             std::list<std::string> lines_;
     138            InputBuffer*              inputBuffer_;
     139            std::stringstream        outputBuffer_;
     140            bool                      bFinishedLastLine_;
     141            std::list<std::string>    outputLines_;
    139142            std::list<std::string>::const_iterator scrollIterator_;
    140             unsigned int scrollPosition_;
    141             std::vector<std::string> commandHistory_;
    142             unsigned int maxHistoryLength_;
    143             unsigned int historyPosition_;
    144             unsigned int historyOffset_;
    145             bool bAddOutputLevel_;
     143            unsigned int              scrollPosition_;
     144            unsigned int              historyPosition_;
     145            ConfigFileType            commandHistoryConfigFileType_;
    146146
    147             ConfigFileType commandHistoryConfigFileType_;
     147            std::string               promptPrefix_;
     148            const std::string         consoleName_;
     149            const bool                bPrependOutputLevel_;
     150            const bool                bScrollable_;
    148151
    149             static Shell* singletonPtr_s;
     152            // Config values
     153            unsigned int              maxHistoryLength_;
     154            unsigned int              historyOffset_;
     155            std::vector<std::string>  commandHistory_;
     156            int                       softDebugLevel_;
    150157    };
    151158}
Note: See TracChangeset for help on using the changeset viewer.