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 <list> |
---|
33 | #include <vector> |
---|
34 | |
---|
35 | #include "CorePrereqs.h" |
---|
36 | |
---|
37 | #include "OrxonoxClass.h" |
---|
38 | #include "InputBuffer.h" |
---|
39 | #include "OutputBuffer.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | class _CoreExport ShellListener |
---|
44 | { |
---|
45 | friend class Shell; |
---|
46 | |
---|
47 | virtual void linesChanged() {} |
---|
48 | virtual void onlyLastLineChanged() {} |
---|
49 | virtual void lineAdded() {} |
---|
50 | virtual void inputChanged() {} |
---|
51 | virtual void cursorChanged() {} |
---|
52 | virtual void exit() {} |
---|
53 | }; |
---|
54 | |
---|
55 | class _CoreExport Shell : virtual public OrxonoxClass, public InputBufferListener, public OutputBufferListener |
---|
56 | { |
---|
57 | public: |
---|
58 | static Shell& getInstance(); |
---|
59 | |
---|
60 | virtual void setConfigValues(); |
---|
61 | |
---|
62 | void registerListener(ShellListener* listener); |
---|
63 | void unregisterListener(ShellListener* listener); |
---|
64 | |
---|
65 | inline InputBuffer& getInputBuffer() |
---|
66 | { return this->inputBuffer_; } |
---|
67 | inline OutputBuffer& getOutputBuffer() |
---|
68 | { return this->outputBuffer_; } |
---|
69 | |
---|
70 | void setCursorPosition(unsigned int cursor); |
---|
71 | inline unsigned int getCursorPosition() const |
---|
72 | { return this->inputBuffer_.getCursorPosition(); } |
---|
73 | |
---|
74 | void setInput(const std::string& input); |
---|
75 | |
---|
76 | inline void clearInput() |
---|
77 | { this->setInput(""); } |
---|
78 | inline std::string getInput() const |
---|
79 | { return this->inputBuffer_.get(); } |
---|
80 | |
---|
81 | std::list<std::string>::const_iterator getNewestLineIterator() const; |
---|
82 | std::list<std::string>::const_iterator getEndIterator() const; |
---|
83 | |
---|
84 | void addLine(const std::string& line, unsigned int level); |
---|
85 | void clearLines(); |
---|
86 | |
---|
87 | inline unsigned int getNumLines() const |
---|
88 | { return this->lines_.size(); } |
---|
89 | inline unsigned int getScrollPosition() const |
---|
90 | { return this->scrollPosition_; } |
---|
91 | |
---|
92 | private: |
---|
93 | Shell(); |
---|
94 | Shell(const Shell& other); |
---|
95 | virtual ~Shell() {} |
---|
96 | |
---|
97 | void addToHistory(const std::string& command); |
---|
98 | std::string getFromHistory() const; |
---|
99 | |
---|
100 | virtual void outputChanged(); |
---|
101 | void inputChanged(); |
---|
102 | void execute(); |
---|
103 | void hintandcomplete(); |
---|
104 | void backspace(); |
---|
105 | void deletechar(); |
---|
106 | void clear(); |
---|
107 | void cursor_right(); |
---|
108 | void cursor_left(); |
---|
109 | void cursor_end(); |
---|
110 | void cursor_home(); |
---|
111 | void history_up(); |
---|
112 | void history_down(); |
---|
113 | void scroll_up(); |
---|
114 | void scroll_down(); |
---|
115 | void exit(); |
---|
116 | |
---|
117 | std::list<ShellListener*> listeners_; |
---|
118 | InputBuffer inputBuffer_; |
---|
119 | OutputBuffer outputBuffer_; |
---|
120 | std::list<std::string> lines_; |
---|
121 | std::list<std::string>::const_iterator scrollIterator_; |
---|
122 | unsigned int scrollPosition_; |
---|
123 | std::vector<std::string> commandHistory_; |
---|
124 | unsigned int maxHistoryLength_; |
---|
125 | unsigned int historyPosition_; |
---|
126 | unsigned int historyOffset_; |
---|
127 | }; |
---|
128 | } |
---|
129 | |
---|
130 | #endif /* _Shell_H__ */ |
---|