Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/command/Shell.h @ 7284

Last change on this file since 7284 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 5.7 KB
RevLine 
[1505]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:
[6105]25 *      Reto Grieder
[1505]26 *
27 */
28
29#ifndef _Shell_H__
30#define _Shell_H__
31
[7203]32#include "core/CorePrereqs.h"
[1792]33
[1505]34#include <list>
[6105]35#include <sstream>
[3196]36#include <string>
[1505]37#include <vector>
38
[6105]39#include "util/OutputHandler.h"
[7203]40#include "core/OrxonoxClass.h"
41#include "core/input/InputBuffer.h"
[1505]42
43namespace orxonox
44{
45    class _CoreExport ShellListener
46    {
47        friend class Shell;
48
49        public:
50            virtual ~ShellListener() {}
51
52        private:
53            virtual void linesChanged() {}
54            virtual void onlyLastLineChanged() {}
55            virtual void lineAdded() {}
56            virtual void inputChanged() {}
57            virtual void cursorChanged() {}
[6105]58            virtual void executed() {}
[1505]59            virtual void exit() {}
60    };
61
[6105]62
63    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
[1505]64    {
65        public:
[6417]66            enum LineType
67            {
68                None    = OutputLevel::None,
69                Warning = OutputLevel::Warning,
70                Error   = OutputLevel::Error,
71                Info    = OutputLevel::Info,
72                Debug   = OutputLevel::Debug,
73                Verbose = OutputLevel::Verbose,
74                Ultra   = OutputLevel::Ultra,
75                Input,
76                Command,
77                Hint
78            };
79
80            Shell(const std::string& consoleName, bool bScrollable);
[6105]81            ~Shell();
[1505]82
[6105]83            void setConfigValues();
[1747]84            void commandHistoryOffsetChanged();
85            void commandHistoryLengthChanged();
[1505]86
87            void registerListener(ShellListener* listener);
88            void unregisterListener(ShellListener* listener);
89
[1755]90            inline InputBuffer* getInputBuffer()
91                { return this->inputBuffer_; }
[1505]92
93            void setCursorPosition(unsigned int cursor);
94            inline unsigned int getCursorPosition() const
95                { return this->inputBuffer_->getCursorPosition(); }
96
[6417]97            inline const std::string& getInput() const
[1505]98                { return this->inputBuffer_->get(); }
99
[6417]100            typedef std::list<std::pair<std::string, LineType> > LineList;
101            LineList::const_iterator getNewestLineIterator() const;
102            LineList::const_iterator getEndIterator() const;
[1505]103
[6417]104            void addOutput(const std::string& text, LineType type = None);
[6105]105            void clearOutput();
[1505]106
107            inline unsigned int getNumLines() const
[6105]108                { return this->outputLines_.size(); }
[1505]109            inline unsigned int getScrollPosition() const
110                { return this->scrollPosition_; }
111
[6105]112            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
113            void setPromptPrefix(const std::string& str);
[1505]114
[7229]115            static inline unsigned int getCacheSize()
116                { return Shell::cacheSize_s; }
117
[1505]118        private:
119            Shell(const Shell& other);
120
121            void addToHistory(const std::string& command);
[6417]122            const std::string& getFromHistory() const;
[6105]123            void clearInput();
124            // OutputListener
125            void outputChanged(int level);
[1505]126
[6105]127            void configureInputBuffer();
128
129            // InputBuffer callbacks
[1505]130            void inputChanged();
131            void execute();
[6105]132            void hintAndComplete();
[1505]133            void backspace();
[6105]134            void deleteChar();
135            void cursorRight();
136            void cursorLeft();
137            void cursorEnd();
138            void cursorHome();
139            void historyUp();
140            void historyDown();
141            void historySearchUp();
142            void historySearchDown();
143            void scrollUp();
144            void scrollDown();
[1505]145            void exit();
146
[6105]147            template <void (ShellListener::*F)()>
148            void updateListeners()
149            {
150                for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
151                    ((*(it++))->*F)();
152            }
153
[1505]154            std::list<ShellListener*> listeners_;
[6105]155            InputBuffer*              inputBuffer_;
156            std::stringstream         outputBuffer_;
157            bool                      bFinishedLastLine_;
[6417]158            LineList                  outputLines_;
159            LineList::const_iterator  scrollIterator_;
[6105]160            unsigned int              scrollPosition_;
161            unsigned int              historyPosition_;
[1792]162
[6105]163            std::string               promptPrefix_;
164            const std::string         consoleName_;
165            const bool                bScrollable_;
[3280]166
[6105]167            // Config values
168            unsigned int              maxHistoryLength_;
169            unsigned int              historyOffset_;
170            std::vector<std::string>  commandHistory_;
171            int                       softDebugLevel_;
[7229]172            static unsigned int       cacheSize_s;
[1505]173    };
174}
175
176#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.