Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1326 was 1326, checked in by landauf, 16 years ago

fixed crash when displaying debug-level 4 and 5 in the InGameConsole. It works perfectly now, although it's not recommended, because you won't see much of your own input in the console any more ;)
however, performance is quite good. maybe i can improve it even more.

File size: 4.2 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, unsigned 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        private:
94            Shell();
95            Shell(const Shell& other);
96            virtual ~Shell() {}
97
98            void addToHistory(const std::string& command);
99            std::string getFromHistory() const;
100
101            virtual void outputChanged();
102            void inputChanged();
103            void execute();
104            void hintandcomplete();
105            void backspace();
106            void deletechar();
107            void clear();
108            void cursor_right();
109            void cursor_left();
110            void cursor_end();
111            void cursor_home();
112            void history_up();
113            void history_down();
114            void scroll_up();
115            void scroll_down();
116            void exit();
117
118            std::list<ShellListener*> listeners_;
119            InputBuffer inputBuffer_;
120            OutputBuffer outputBuffer_;
121            bool finishedLastLine_;
122            std::list<std::string> lines_;
123            std::list<std::string>::const_iterator scrollIterator_;
124            unsigned int scrollPosition_;
125            std::vector<std::string> commandHistory_;
126            unsigned int maxHistoryLength_;
127            unsigned int historyPosition_;
128            unsigned int historyOffset_;
129    };
130}
131
132#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.