Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/Shell.h @ 1417

Last change on this file since 1417 was 1334, checked in by landauf, 16 years ago
  • added colored output in the InGameConsole, depending on the output level (error = red, …).
  • increased performance of InGameConsole and Shell
File size: 4.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Shell_H__
30#define _Shell_H__
31
32#include <list>
33#include <vector>
34
35#include "CorePrereqs.h"
36
37#include "OrxonoxClass.h"
38#include "InputBuffer.h"
39#include "OutputBuffer.h"
40
41namespace orxonox
42{
43    class _CoreExport ShellListener
44    {
45        friend class Shell;
46
47        virtual void linesChanged() {}
48        virtual void onlyLastLineChanged() {}
49        virtual void lineAdded() {}
50        virtual void inputChanged() {}
51        virtual void cursorChanged() {}
52        virtual void exit() {}
53    };
54
55    class _CoreExport Shell : virtual public OrxonoxClass, public InputBufferListener, public OutputBufferListener
56    {
57        public:
58            static Shell& getInstance();
59            static Shell& createShell();
60
61            virtual void setConfigValues();
62
63            void registerListener(ShellListener* listener);
64            void unregisterListener(ShellListener* listener);
65
66            inline InputBuffer& getInputBuffer()
67                { return this->inputBuffer_; }
68            inline OutputBuffer& getOutputBuffer()
69                { return this->outputBuffer_; }
70
71            void setCursorPosition(unsigned int cursor);
72            inline unsigned int getCursorPosition() const
73                { return this->inputBuffer_.getCursorPosition(); }
74
75            void setInput(const std::string& input);
76
77            inline void clearInput()
78                { this->setInput(""); }
79            inline std::string getInput() const
80                { return this->inputBuffer_.get(); }
81
82            std::list<std::string>::const_iterator getNewestLineIterator() const;
83            std::list<std::string>::const_iterator getEndIterator() const;
84
85            void addLine(const std::string& line, int level);
86            void clearLines();
87
88            inline unsigned int getNumLines() const
89                { return this->lines_.size(); }
90            inline unsigned int getScrollPosition() const
91                { return this->scrollPosition_; }
92
93            inline void addOutputLevel(bool bAddOutputLevel)
94                { this->bAddOutputLevel_ = bAddOutputLevel; }
95
96        private:
97            Shell();
98            Shell(const Shell& other);
99            virtual ~Shell() {}
100
101            void addToHistory(const std::string& command);
102            std::string getFromHistory() const;
103
104            virtual void outputChanged();
105            void inputChanged();
106            void execute();
107            void hintandcomplete();
108            void backspace();
109            void deletechar();
110            void clear();
111            void cursor_right();
112            void cursor_left();
113            void cursor_end();
114            void cursor_home();
115            void history_up();
116            void history_down();
117            void scroll_up();
118            void scroll_down();
119            void exit();
120
121            std::list<ShellListener*> listeners_;
122            InputBuffer inputBuffer_;
123            OutputBuffer outputBuffer_;
124            bool finishedLastLine_;
125            std::list<std::string> lines_;
126            std::list<std::string>::const_iterator scrollIterator_;
127            unsigned int scrollPosition_;
128            std::vector<std::string> commandHistory_;
129            unsigned int maxHistoryLength_;
130            unsigned int historyPosition_;
131            unsigned int historyOffset_;
132            bool bAddOutputLevel_;
133    };
134}
135
136#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.