Changeset 6412 for code/branches/pickup2/src/libraries/core/Shell.h
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/libraries/core/Shell.h
r5781 r6412 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 32 32 #include "CorePrereqs.h" 33 33 34 #include <cassert>35 34 #include <list> 35 #include <sstream> 36 36 #include <string> 37 37 #include <vector> 38 38 39 #include "util/OutputBuffer.h" 40 #include "input/InputBuffer.h" 39 #include "util/OutputHandler.h" 41 40 #include "OrxonoxClass.h" 42 41 #include "ConfigFileManager.h" 42 #include "input/InputBuffer.h" 43 43 44 44 namespace orxonox … … 57 57 virtual void inputChanged() {} 58 58 virtual void cursorChanged() {} 59 virtual void executed() {} 59 60 virtual void exit() {} 60 61 }; 61 62 62 class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener 63 64 class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener 63 65 { 64 friend class Singleton<Shell>;65 66 public: 66 Shell(); 67 virtual ~Shell(); 67 enum LineType 68 { 69 None = OutputLevel::None, 70 Warning = OutputLevel::Warning, 71 Error = OutputLevel::Error, 72 Info = OutputLevel::Info, 73 Debug = OutputLevel::Debug, 74 Verbose = OutputLevel::Verbose, 75 Ultra = OutputLevel::Ultra, 76 Input, 77 Command, 78 Hint 79 }; 68 80 69 static void clearShell();70 static void history();81 Shell(const std::string& consoleName, bool bScrollable); 82 ~Shell(); 71 83 72 v irtual void setConfigValues();84 void setConfigValues(); 73 85 void commandHistoryOffsetChanged(); 74 86 void commandHistoryLengthChanged(); … … 79 91 inline InputBuffer* getInputBuffer() 80 92 { return this->inputBuffer_; } 81 inline OutputBuffer& getOutputBuffer()82 { return this->outputBuffer_; }83 93 84 94 void setCursorPosition(unsigned int cursor); … … 86 96 { return this->inputBuffer_->getCursorPosition(); } 87 97 88 void setInput(const std::string& input); 89 90 inline void clearInput() 91 { this->setInput(""); } 92 inline std::string getInput() const 98 inline const std::string& getInput() const 93 99 { return this->inputBuffer_->get(); } 94 100 95 std::list<std::string>::const_iterator getNewestLineIterator() const; 96 std::list<std::string>::const_iterator getEndIterator() const; 101 typedef std::list<std::pair<std::string, LineType> > LineList; 102 LineList::const_iterator getNewestLineIterator() const; 103 LineList::const_iterator getEndIterator() const; 97 104 98 void add Line(const std::string& line, int level = 0);99 void clear Lines();105 void addOutput(const std::string& text, LineType type = None); 106 void clearOutput(); 100 107 101 108 inline unsigned int getNumLines() const 102 { return this-> lines_.size(); }109 { return this->outputLines_.size(); } 103 110 inline unsigned int getScrollPosition() const 104 111 { return this->scrollPosition_; } 105 112 106 inline void addOutputLevel(bool bAddOutputLevel)107 { this->bAddOutputLevel_ = bAddOutputLevel; }113 inline const std::string& getPromptPrefix() const { return this->promptPrefix_; } 114 void setPromptPrefix(const std::string& str); 108 115 109 116 private: 110 117 Shell(const Shell& other); 111 118 119 void addToHistory(const std::string& command); 120 const std::string& getFromHistory() const; 121 void clearInput(); 122 // OutputListener 123 void outputChanged(int level); 124 112 125 void configureInputBuffer(); 113 126 114 void addToHistory(const std::string& command); 115 std::string getFromHistory() const; 116 117 virtual void outputChanged(); 127 // InputBuffer callbacks 118 128 void inputChanged(); 119 129 void execute(); 120 void hint andcomplete();130 void hintAndComplete(); 121 131 void backspace(); 122 void deletechar(); 123 void clear(); 124 void cursor_right(); 125 void cursor_left(); 126 void cursor_end(); 127 void cursor_home(); 128 void history_up(); 129 void history_down(); 130 void scroll_up(); 131 void scroll_down(); 132 void deleteChar(); 133 void cursorRight(); 134 void cursorLeft(); 135 void cursorEnd(); 136 void cursorHome(); 137 void historyUp(); 138 void historyDown(); 139 void historySearchUp(); 140 void historySearchDown(); 141 void scrollUp(); 142 void scrollDown(); 132 143 void exit(); 133 144 145 template <void (ShellListener::*F)()> 146 void updateListeners() 147 { 148 for (std::list<ShellListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 149 ((*(it++))->*F)(); 150 } 151 134 152 std::list<ShellListener*> listeners_; 135 InputBuffer* inputBuffer_; 136 OutputBuffer outputBuffer_; 137 bool finishedLastLine_; 138 std::list<std::string> lines_; 139 std::list<std::string>::const_iterator scrollIterator_; 140 unsigned int scrollPosition_; 141 std::vector<std::string> commandHistory_; 142 unsigned int maxHistoryLength_; 143 unsigned int historyPosition_; 144 unsigned int historyOffset_; 145 bool bAddOutputLevel_; 153 InputBuffer* inputBuffer_; 154 std::stringstream outputBuffer_; 155 bool bFinishedLastLine_; 156 LineList outputLines_; 157 LineList::const_iterator scrollIterator_; 158 unsigned int scrollPosition_; 159 unsigned int historyPosition_; 146 160 147 ConfigFileType commandHistoryConfigFileType_; 161 std::string promptPrefix_; 162 const std::string consoleName_; 163 const bool bScrollable_; 148 164 149 static Shell* singletonPtr_s; 165 // Config values 166 unsigned int maxHistoryLength_; 167 unsigned int historyOffset_; 168 std::vector<std::string> commandHistory_; 169 int softDebugLevel_; 150 170 }; 151 171 }
Note: See TracChangeset
for help on using the changeset viewer.