Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6010 was 6010, checked in by rgrieder, 14 years ago

Sorted out some small stuff in the Shell and hopefully fixed IOConsole problems (flickering and too much output).

  • Property svn:eol-style set to native
File size: 5.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 *      Reto Grieder
26 *
27 */
28
29#ifndef _Shell_H__
30#define _Shell_H__
31
32#include "CorePrereqs.h"
33
34#include <list>
35#include <sstream>
36#include <string>
37#include <vector>
38
39#include "util/OutputHandler.h"
40#include "OrxonoxClass.h"
41#include "ConfigFileManager.h"
42#include "input/InputBuffer.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 executed() {}
60            virtual void exit() {}
61    };
62
63
64    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
65    {
66        public:
67            Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false);
68            ~Shell();
69
70            void setConfigValues();
71            void commandHistoryOffsetChanged();
72            void commandHistoryLengthChanged();
73
74            void registerListener(ShellListener* listener);
75            void unregisterListener(ShellListener* listener);
76
77            inline InputBuffer* getInputBuffer()
78                { return this->inputBuffer_; }
79
80            void setCursorPosition(unsigned int cursor);
81            inline unsigned int getCursorPosition() const
82                { return this->inputBuffer_->getCursorPosition(); }
83
84            inline std::string getInput() const
85                { return this->inputBuffer_->get(); }
86
87            std::list<std::string>::const_iterator getNewestLineIterator() const;
88            std::list<std::string>::const_iterator getEndIterator() const;
89
90            void addOutputLine(const std::string& line, int level = 0);
91            void clearOutput();
92
93            inline unsigned int getNumLines() const
94                { return this->outputLines_.size(); }
95            inline unsigned int getScrollPosition() const
96                { return this->scrollPosition_; }
97
98            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
99            void setPromptPrefix(const std::string& str);
100
101        private:
102            Shell(const Shell& other);
103
104            void addToHistory(const std::string& command);
105            std::string getFromHistory() const;
106            void clearInput();
107            // OutputListener
108            void outputChanged(int level);
109
110            void configureInputBuffer();
111
112            // InputBuffer callbacks
113            void inputChanged();
114            void execute();
115            void hintAndComplete();
116            void backspace();
117            void deleteChar();
118            void cursorRight();
119            void cursorLeft();
120            void cursorEnd();
121            void cursorHome();
122            void historyUp();
123            void historyDown();
124            void historySearchUp();
125            void historySearchDown();
126            void scrollUp();
127            void scrollDown();
128            void exit();
129
130            template <void (ShellListener::*F)()>
131            void updateListeners()
132            {
133                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
134                    ((*(it++))->*F)();
135            }
136
137            std::list<ShellListener*> listeners_;
138            InputBuffer*              inputBuffer_;
139            std::stringstream         outputBuffer_;
140            bool                      bFinishedLastLine_;
141            std::list<std::string>    outputLines_;
142            std::list<std::string>::const_iterator scrollIterator_;
143            unsigned int              scrollPosition_;
144            unsigned int              historyPosition_;
145            ConfigFileType            commandHistoryConfigFileType_;
146
147            std::string               promptPrefix_;
148            const std::string         consoleName_;
149            const bool                bPrependOutputLevel_;
150            const bool                bScrollable_;
151
152            // Config values
153            unsigned int              maxHistoryLength_;
154            unsigned int              historyOffset_;
155            std::vector<std::string>  commandHistory_;
156            int                       softDebugLevel_;
157    };
158}
159
160#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.