Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5986 was 5986, checked in by scheusso, 15 years ago

added a new feature to the IOConsole: you can now search the history (like in bash shells) with PgUP
just enter a few signs/characters of a command you once typed in and press PgUP to complete the command
if the found command is not the one you were looking for just press PgUP again

  • Property svn:eol-style set to native
File size: 5.1 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 executed() {}
60            virtual void exit() {}
61    };
62
63    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
64    {
65        friend class Singleton<Shell>;
66        public:
67            Shell();
68            virtual ~Shell();
69
70            static void clearShell();
71            static void history();
72
73            virtual void setConfigValues();
74            void commandHistoryOffsetChanged();
75            void commandHistoryLengthChanged();
76
77            void registerListener(ShellListener* listener);
78            void unregisterListener(ShellListener* listener);
79
80            inline InputBuffer* getInputBuffer()
81                { return this->inputBuffer_; }
82            inline OutputBuffer& getOutputBuffer()
83                { return this->outputBuffer_; }
84
85            void setCursorPosition(unsigned int cursor);
86            inline unsigned int getCursorPosition() const
87                { return this->inputBuffer_->getCursorPosition(); }
88
89            void setInput(const std::string& input);
90
91            inline void clearInput()
92                { this->setInput(""); }
93            inline std::string getInput() const
94                { return this->inputBuffer_->get(); }
95
96            std::list<std::string>::const_iterator getNewestLineIterator() const;
97            std::list<std::string>::const_iterator getEndIterator() const;
98
99            void addLine(const std::string& line, int level = 0);
100            void clearLines();
101
102            inline unsigned int getNumLines() const
103                { return this->lines_.size(); }
104            inline unsigned int getScrollPosition() const
105                { return this->scrollPosition_; }
106
107            inline void addOutputLevel(bool bAddOutputLevel)
108                { this->bAddOutputLevel_ = bAddOutputLevel; }
109
110        private:
111            Shell(const Shell& other);
112
113            void configureInputBuffer();
114
115            void addToHistory(const std::string& command);
116            std::string getFromHistory() const;
117
118            virtual void outputChanged();
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            OutputBuffer 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
157            ConfigFileType commandHistoryConfigFileType_;
158
159            static Shell* singletonPtr_s;
160    };
161}
162
163#endif /* _Shell_H__ */
Note: See TracBrowser for help on using the repository browser.