Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changed Output concept a little bit to allow for more general use.
Every output (log) target has to be implemented as OutputListener. There is already a LogFileWriter and a MemoryLogWriter (stores ALL the log in a vector and provides iterators).
The OutputListener has a unique and constant name, a stream pointer and a soft debug level (that can only be changed via OutputHandler::setSoftDebugLevel(name, level)).
This concept doesn't require the OutputBuffer anymore, so I deleted it.

The adjustments in the Shell are just preliminary for this commit.

  • Property svn:eol-style set to native
File size: 5.0 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 <sstream>
37#include <string>
38#include <vector>
39
40#include "util/OutputHandler.h"
41#include "input/InputBuffer.h"
42#include "OrxonoxClass.h"
43#include "ConfigFileManager.h"
44
45namespace orxonox
46{
47    class _CoreExport ShellListener
48    {
49        friend class Shell;
50
51        public:
52            virtual ~ShellListener() {}
53
54        private:
55            virtual void linesChanged() {}
56            virtual void onlyLastLineChanged() {}
57            virtual void lineAdded() {}
58            virtual void inputChanged() {}
59            virtual void cursorChanged() {}
60            virtual void executed() {}
61            virtual void exit() {}
62    };
63
64    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputListener
65    {
66        friend class Singleton<Shell>;
67        public:
68            Shell();
69            virtual ~Shell();
70
71            static void clearShell();
72            static void history();
73
74            void setConfigValues();
75            void commandHistoryOffsetChanged();
76            void commandHistoryLengthChanged();
77
78            void registerListener(ShellListener* listener);
79            void unregisterListener(ShellListener* listener);
80
81            inline InputBuffer* getInputBuffer()
82                { return this->inputBuffer_; }
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
119            void inputChanged();
120            void execute();
121            void hintandcomplete();
122            void backspace();
123            void deletechar();
124            void clear();
125            void cursor_right();
126            void cursor_left();
127            void cursor_end();
128            void cursor_home();
129            void history_up();
130            void history_down();
131            void history_search_up();
132            void history_search_down();
133            void scroll_up();
134            void scroll_down();
135            void exit();
136
137            template <void (ShellListener::*F)()>
138            void updateListeners()
139            {
140                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
141                    ((*(it++))->*F)();
142            }
143
144            std::list<ShellListener*> listeners_;
145            InputBuffer* inputBuffer_;
146            std::stringstream outputBuffer_;
147            bool finishedLastLine_;
148            std::list<std::string> lines_;
149            std::list<std::string>::const_iterator scrollIterator_;
150            unsigned int scrollPosition_;
151            std::vector<std::string> commandHistory_;
152            unsigned int maxHistoryLength_;
153            unsigned int historyPosition_;
154            unsigned int historyOffset_;
155            bool bAddOutputLevel_;
156            int softDebugLevel_;
157
158            ConfigFileType commandHistoryConfigFileType_;
159
160            static Shell* singletonPtr_s;
161    };
162}
163
164#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.