Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource/src/core/Shell.h @ 5732

Last change on this file since 5732 was 3366, checked in by rgrieder, 15 years ago

Derived all singletons implemented in a usual manner from orxonox::Singleton<T>.
This resolves inconsistencies with the singletonPtr_s variable in case of exceptions (asserts were being triggered then).
And while at it replaced singletonRef_s with singletonPtr_s for it to be less misleading (as fabian has already pointed out).

  • Property svn:eol-style set to native
File size: 4.7 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 "CorePrereqs.h"
33
34#include <cassert>
35#include <list>
36#include <string>
37#include <vector>
38
39#include "util/OutputBuffer.h"
40#include "input/InputBuffer.h"
41#include "OrxonoxClass.h"
42#include "ConfigFileManager.h"
43
44namespace orxonox
45{
46    class _CoreExport ShellListener
47    {
48        friend class Shell;
49
50        public:
51            virtual ~ShellListener() {}
52
53        private:
54            virtual void linesChanged() {}
55            virtual void onlyLastLineChanged() {}
56            virtual void lineAdded() {}
57            virtual void inputChanged() {}
58            virtual void cursorChanged() {}
59            virtual void exit() {}
60    };
61
62    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
63    {
64        friend class Singleton<Shell>;
65        public:
66            Shell();
67            virtual ~Shell();
68
69            static void clearShell();
70            static void history();
71
72            virtual void setConfigValues();
73            void commandHistoryOffsetChanged();
74            void commandHistoryLengthChanged();
75
76            void registerListener(ShellListener* listener);
77            void unregisterListener(ShellListener* listener);
78
79            inline InputBuffer* getInputBuffer()
80                { return this->inputBuffer_; }
81            inline OutputBuffer& getOutputBuffer()
82                { return this->outputBuffer_; }
83
84            void setCursorPosition(unsigned int cursor);
85            inline unsigned int getCursorPosition() const
86                { return this->inputBuffer_->getCursorPosition(); }
87
88            void setInput(const std::string& input);
89
90            inline void clearInput()
91                { this->setInput(""); }
92            inline std::string getInput() const
93                { return this->inputBuffer_->get(); }
94
95            std::list<std::string>::const_iterator getNewestLineIterator() const;
96            std::list<std::string>::const_iterator getEndIterator() const;
97
98            void addLine(const std::string& line, int level = 0);
99            void clearLines();
100
101            inline unsigned int getNumLines() const
102                { return this->lines_.size(); }
103            inline unsigned int getScrollPosition() const
104                { return this->scrollPosition_; }
105
106            inline void addOutputLevel(bool bAddOutputLevel)
107                { this->bAddOutputLevel_ = bAddOutputLevel; }
108
109        private:
110            Shell(const Shell& other);
111
112            void configureInputBuffer();
113
114            void addToHistory(const std::string& command);
115            std::string getFromHistory() const;
116
117            virtual void outputChanged();
118            void inputChanged();
119            void execute();
120            void hintandcomplete();
121            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 exit();
133
134            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_;
146
147            ConfigFileType commandHistoryConfigFileType_;
148
149            static Shell* singletonPtr_s;
150    };
151}
152
153#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.