[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 | |
---|
| 32 | #include <list> |
---|
| 33 | #include <vector> |
---|
| 34 | |
---|
| 35 | #include "CorePrereqs.h" |
---|
| 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: |
---|
| 62 | static Shell& getInstance(); |
---|
| 63 | static Shell& createShell(); |
---|
| 64 | |
---|
| 65 | static void clearShell(); |
---|
| 66 | static void history(); |
---|
| 67 | |
---|
| 68 | virtual void setConfigValues(); |
---|
[1747] | 69 | void commandHistoryOffsetChanged(); |
---|
| 70 | void commandHistoryLengthChanged(); |
---|
[1505] | 71 | |
---|
| 72 | void registerListener(ShellListener* listener); |
---|
| 73 | void unregisterListener(ShellListener* listener); |
---|
| 74 | |
---|
| 75 | void setInputBuffer(InputBuffer* buffer); |
---|
| 76 | inline InputBuffer& getInputBuffer() |
---|
| 77 | { return (*this->inputBuffer_); } |
---|
| 78 | inline OutputBuffer& getOutputBuffer() |
---|
| 79 | { return this->outputBuffer_; } |
---|
| 80 | |
---|
| 81 | void setCursorPosition(unsigned int cursor); |
---|
| 82 | inline unsigned int getCursorPosition() const |
---|
| 83 | { return this->inputBuffer_->getCursorPosition(); } |
---|
| 84 | |
---|
| 85 | void setInput(const std::string& input); |
---|
| 86 | |
---|
| 87 | inline void clearInput() |
---|
| 88 | { this->setInput(""); } |
---|
| 89 | inline std::string getInput() const |
---|
| 90 | { return this->inputBuffer_->get(); } |
---|
| 91 | |
---|
| 92 | std::list<std::string>::const_iterator getNewestLineIterator() const; |
---|
| 93 | std::list<std::string>::const_iterator getEndIterator() const; |
---|
| 94 | |
---|
| 95 | void addLine(const std::string& line, int level = 0); |
---|
| 96 | void clearLines(); |
---|
| 97 | |
---|
| 98 | inline unsigned int getNumLines() const |
---|
| 99 | { return this->lines_.size(); } |
---|
| 100 | inline unsigned int getScrollPosition() const |
---|
| 101 | { return this->scrollPosition_; } |
---|
| 102 | |
---|
| 103 | inline void addOutputLevel(bool bAddOutputLevel) |
---|
| 104 | { this->bAddOutputLevel_ = bAddOutputLevel; } |
---|
| 105 | |
---|
| 106 | private: |
---|
| 107 | Shell(); |
---|
| 108 | Shell(const Shell& other); |
---|
| 109 | virtual ~Shell() {} |
---|
| 110 | |
---|
| 111 | void addToHistory(const std::string& command); |
---|
| 112 | std::string getFromHistory() const; |
---|
| 113 | |
---|
| 114 | virtual void outputChanged(); |
---|
| 115 | void inputChanged(); |
---|
| 116 | void execute(); |
---|
| 117 | void hintandcomplete(); |
---|
| 118 | void backspace(); |
---|
| 119 | void deletechar(); |
---|
| 120 | void clear(); |
---|
| 121 | void cursor_right(); |
---|
| 122 | void cursor_left(); |
---|
| 123 | void cursor_end(); |
---|
| 124 | void cursor_home(); |
---|
| 125 | void history_up(); |
---|
| 126 | void history_down(); |
---|
| 127 | void scroll_up(); |
---|
| 128 | void scroll_down(); |
---|
| 129 | void exit(); |
---|
| 130 | |
---|
| 131 | std::list<ShellListener*> listeners_; |
---|
| 132 | InputBuffer* inputBuffer_; |
---|
| 133 | OutputBuffer outputBuffer_; |
---|
| 134 | bool finishedLastLine_; |
---|
| 135 | std::list<std::string> lines_; |
---|
| 136 | std::list<std::string>::const_iterator scrollIterator_; |
---|
| 137 | unsigned int scrollPosition_; |
---|
| 138 | std::vector<std::string> commandHistory_; |
---|
| 139 | unsigned int maxHistoryLength_; |
---|
| 140 | unsigned int historyPosition_; |
---|
| 141 | unsigned int historyOffset_; |
---|
| 142 | bool bAddOutputLevel_; |
---|
| 143 | }; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | #endif /* _Shell_H__ */ |
---|