[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 | |
---|
[1792] | 32 | #include "CorePrereqs.h" |
---|
| 33 | |
---|
[1505] | 34 | #include <list> |
---|
[6105] | 35 | #include <sstream> |
---|
[3196] | 36 | #include <string> |
---|
[1505] | 37 | #include <vector> |
---|
| 38 | |
---|
[6105] | 39 | #include "util/OutputHandler.h" |
---|
[1505] | 40 | #include "OrxonoxClass.h" |
---|
[3280] | 41 | #include "ConfigFileManager.h" |
---|
[6105] | 42 | #include "input/InputBuffer.h" |
---|
[1505] | 43 | |
---|
| 44 | namespace 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() {} |
---|
[6105] | 59 | virtual void executed() {} |
---|
[1505] | 60 | virtual void exit() {} |
---|
| 61 | }; |
---|
| 62 | |
---|
[6105] | 63 | |
---|
| 64 | class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener |
---|
[1505] | 65 | { |
---|
| 66 | public: |
---|
[6105] | 67 | Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false); |
---|
| 68 | ~Shell(); |
---|
[1505] | 69 | |
---|
[6105] | 70 | 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 | |
---|
| 80 | void setCursorPosition(unsigned int cursor); |
---|
| 81 | inline unsigned int getCursorPosition() const |
---|
| 82 | { return this->inputBuffer_->getCursorPosition(); } |
---|
| 83 | |
---|
| 84 | inline std::string getInput() const |
---|
| 85 | { return this->inputBuffer_->get(); } |
---|
| 86 | |
---|
| 87 | std::list<std::string>::const_iterator getNewestLineIterator() const; |
---|
| 88 | std::list<std::string>::const_iterator getEndIterator() const; |
---|
| 89 | |
---|
[6105] | 90 | void addOutputLine(const std::string& line, int level = 0); |
---|
| 91 | void clearOutput(); |
---|
[1505] | 92 | |
---|
| 93 | inline unsigned int getNumLines() const |
---|
[6105] | 94 | { return this->outputLines_.size(); } |
---|
[1505] | 95 | inline unsigned int getScrollPosition() const |
---|
| 96 | { return this->scrollPosition_; } |
---|
| 97 | |
---|
[6105] | 98 | inline const std::string& getPromptPrefix() const { return this->promptPrefix_; } |
---|
| 99 | void setPromptPrefix(const std::string& str); |
---|
[1505] | 100 | |
---|
| 101 | private: |
---|
| 102 | Shell(const Shell& other); |
---|
| 103 | |
---|
| 104 | void addToHistory(const std::string& command); |
---|
| 105 | std::string getFromHistory() const; |
---|
[6105] | 106 | void clearInput(); |
---|
| 107 | // OutputListener |
---|
| 108 | void outputChanged(int level); |
---|
[1505] | 109 | |
---|
[6105] | 110 | void configureInputBuffer(); |
---|
| 111 | |
---|
| 112 | // InputBuffer callbacks |
---|
[1505] | 113 | void inputChanged(); |
---|
| 114 | void execute(); |
---|
[6105] | 115 | void hintAndComplete(); |
---|
[1505] | 116 | void backspace(); |
---|
[6105] | 117 | void deleteChar(); |
---|
| 118 | void cursorRight(); |
---|
| 119 | void cursorLeft(); |
---|
| 120 | void cursorEnd(); |
---|
| 121 | void cursorHome(); |
---|
| 122 | void historyUp(); |
---|
| 123 | void historyDown(); |
---|
| 124 | void historySearchUp(); |
---|
| 125 | void historySearchDown(); |
---|
| 126 | void scrollUp(); |
---|
| 127 | void scrollDown(); |
---|
[1505] | 128 | void exit(); |
---|
| 129 | |
---|
[6105] | 130 | template <void (ShellListener::*F)()> |
---|
| 131 | void updateListeners() |
---|
| 132 | { |
---|
| 133 | for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) |
---|
| 134 | ((*(it++))->*F)(); |
---|
| 135 | } |
---|
| 136 | |
---|
[1505] | 137 | std::list<ShellListener*> listeners_; |
---|
[6105] | 138 | InputBuffer* inputBuffer_; |
---|
| 139 | std::stringstream outputBuffer_; |
---|
| 140 | bool bFinishedLastLine_; |
---|
| 141 | std::list<std::string> outputLines_; |
---|
[1505] | 142 | std::list<std::string>::const_iterator scrollIterator_; |
---|
[6105] | 143 | unsigned int scrollPosition_; |
---|
| 144 | unsigned int historyPosition_; |
---|
| 145 | ConfigFileType commandHistoryConfigFileType_; |
---|
[1792] | 146 | |
---|
[6105] | 147 | std::string promptPrefix_; |
---|
| 148 | const std::string consoleName_; |
---|
| 149 | const bool bPrependOutputLevel_; |
---|
| 150 | const bool bScrollable_; |
---|
[3280] | 151 | |
---|
[6105] | 152 | // Config values |
---|
| 153 | unsigned int maxHistoryLength_; |
---|
| 154 | unsigned int historyOffset_; |
---|
| 155 | std::vector<std::string> commandHistory_; |
---|
| 156 | int softDebugLevel_; |
---|
[1505] | 157 | }; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | #endif /* _Shell_H__ */ |
---|