Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 1:18:03 PM (15 years ago)
Author:
dafrick
Message:

Merged presentation2 branch into pickup2 branch.

Location:
code/branches/pickup2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup2

  • code/branches/pickup2/src/libraries/core/Shell.h

    r5781 r6412  
    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            enum LineType
     68            {
     69                None    = OutputLevel::None,
     70                Warning = OutputLevel::Warning,
     71                Error   = OutputLevel::Error,
     72                Info    = OutputLevel::Info,
     73                Debug   = OutputLevel::Debug,
     74                Verbose = OutputLevel::Verbose,
     75                Ultra   = OutputLevel::Ultra,
     76                Input,
     77                Command,
     78                Hint
     79            };
    6880
    69             static void clearShell();
    70             static void history();
     81            Shell(const std::string& consoleName, bool bScrollable);
     82            ~Shell();
    7183
    72             virtual void setConfigValues();
     84            void setConfigValues();
    7385            void commandHistoryOffsetChanged();
    7486            void commandHistoryLengthChanged();
     
    7991            inline InputBuffer* getInputBuffer()
    8092                { return this->inputBuffer_; }
    81             inline OutputBuffer& getOutputBuffer()
    82                 { return this->outputBuffer_; }
    8393
    8494            void setCursorPosition(unsigned int cursor);
     
    8696                { return this->inputBuffer_->getCursorPosition(); }
    8797
    88             void setInput(const std::string& input);
    89 
    90             inline void clearInput()
    91                 { this->setInput(""); }
    92             inline std::string getInput() const
     98            inline const std::string& getInput() const
    9399                { return this->inputBuffer_->get(); }
    94100
    95             std::list<std::string>::const_iterator getNewestLineIterator() const;
    96             std::list<std::string>::const_iterator getEndIterator() const;
     101            typedef std::list<std::pair<std::string, LineType> > LineList;
     102            LineList::const_iterator getNewestLineIterator() const;
     103            LineList::const_iterator getEndIterator() const;
    97104
    98             void addLine(const std::string& line, int level = 0);
    99             void clearLines();
     105            void addOutput(const std::string& text, LineType type = None);
     106            void clearOutput();
    100107
    101108            inline unsigned int getNumLines() const
    102                 { return this->lines_.size(); }
     109                { return this->outputLines_.size(); }
    103110            inline unsigned int getScrollPosition() const
    104111                { return this->scrollPosition_; }
    105112
    106             inline void addOutputLevel(bool bAddOutputLevel)
    107                 { this->bAddOutputLevel_ = bAddOutputLevel; }
     113            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
     114            void setPromptPrefix(const std::string& str);
    108115
    109116        private:
    110117            Shell(const Shell& other);
    111118
     119            void addToHistory(const std::string& command);
     120            const std::string& getFromHistory() const;
     121            void clearInput();
     122            // OutputListener
     123            void outputChanged(int level);
     124
    112125            void configureInputBuffer();
    113126
    114             void addToHistory(const std::string& command);
    115             std::string getFromHistory() const;
    116 
    117             virtual void outputChanged();
     127            // InputBuffer callbacks
    118128            void inputChanged();
    119129            void execute();
    120             void hintandcomplete();
     130            void hintAndComplete();
    121131            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();
     132            void deleteChar();
     133            void cursorRight();
     134            void cursorLeft();
     135            void cursorEnd();
     136            void cursorHome();
     137            void historyUp();
     138            void historyDown();
     139            void historySearchUp();
     140            void historySearchDown();
     141            void scrollUp();
     142            void scrollDown();
    132143            void exit();
    133144
     145            template <void (ShellListener::*F)()>
     146            void updateListeners()
     147            {
     148                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
     149                    ((*(it++))->*F)();
     150            }
     151
    134152            std::list<ShellListener*> listeners_;
    135             InputBuffer* inputBuffer_;
    136             OutputBuffer outputBuffer_;
    137             bool finishedLastLine_;
    138             std::list<std::string> lines_;
    139             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_;
     153            InputBuffer*              inputBuffer_;
     154            std::stringstream         outputBuffer_;
     155            bool                      bFinishedLastLine_;
     156            LineList                  outputLines_;
     157            LineList::const_iterator  scrollIterator_;
     158            unsigned int              scrollPosition_;
     159            unsigned int              historyPosition_;
    146160
    147             ConfigFileType commandHistoryConfigFileType_;
     161            std::string               promptPrefix_;
     162            const std::string         consoleName_;
     163            const bool                bScrollable_;
    148164
    149             static Shell* singletonPtr_s;
     165            // Config values
     166            unsigned int              maxHistoryLength_;
     167            unsigned int              historyOffset_;
     168            std::vector<std::string>  commandHistory_;
     169            int                       softDebugLevel_;
    150170    };
    151171}
Note: See TracChangeset for help on using the changeset viewer.