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