Changeset 7343 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Apr 19, 2006, 4:26:27 AM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_completion.cc
r7319 r7343 32 32 33 33 /** 34 * standard constructor 35 */ 36 ShellCompletion::ShellCompletion(ShellInput* input) 37 { 38 this->input = input; 39 } 40 41 42 /** 43 * standard deconstructor 34 * @brief standard constructor 35 */ 36 ShellCompletion::ShellCompletion() 37 { } 38 39 40 /** 41 * @brief standard deconstructor 44 42 */ 45 43 ShellCompletion::~ShellCompletion () 46 { 47 } 48 49 50 51 /** 52 * autocompletes the Shell's inputLine 44 { } 45 46 47 48 /** 49 * @brief autocompletes the Shell's inputLine 53 50 * @returns true, if a result was found, false otherwise 54 51 */ 55 bool ShellCompletion::autoComplete( ShellInput*input)52 bool ShellCompletion::autoComplete(std::string& input) 56 53 { 57 54 const char* completionLine; //< the inputLine we complete. … … 67 64 this->emptyCompletionList(); 68 65 69 if (input != NULL)70 this->input = input;71 if (this->input == NULL)72 {73 PRINTF(2)("No ShellInput supplied\n");74 return false;75 }76 77 66 // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object 78 if ( this->input->getInput()[this->input->getInput().size()-1] == ' ')67 if (input[input.size()-1] == ' ') 79 68 { 80 69 emptyComplete = true; … … 82 71 83 72 // CREATE INPUTS 84 SubString inputSplits( this->input->getInput(), " \t\n,");73 SubString inputSplits(input, " \t\n,"); 85 74 86 75 // What String will be completed … … 133 122 134 123 135 this->generalComplete( completeString);136 return true; 137 } 138 139 /** 140 * autocompletes a className124 this->generalComplete(input, completeString); 125 return true; 126 } 127 128 /** 129 * @brief autocompletes a className 141 130 * @param classBegin the Beginning of a String to autoComplete 142 131 * @return true on success, false otherwise … … 156 145 157 146 /** 158 * autocompletes an ObjectName147 * @brief autocompletes an ObjectName 159 148 * @param objectBegin the beginning string of a Object 160 149 * @param classID the ID of the Class to search for. … … 178 167 179 168 /** 180 * completes a Function169 * @brief completes a Function 181 170 * @param functionBegin the beginning of the function String 182 171 * @param classID the class' ID to complete the function of … … 193 182 194 183 /** 195 * completes an Alias184 * @brief completes an Alias 196 185 * @param aliasBegin the beginning of the Alias-String to complete 197 186 * @returns true on succes, false if something went wrong … … 209 198 210 199 /** 211 * completes the inputline on grounds of an inputList200 * @brief completes the inputline on grounds of an inputList 212 201 * @param begin the String to search in the inputList, and to extend with it. 213 202 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::" … … 216 205 * @return true if ok, false otherwise 217 206 */ 218 bool ShellCompletion::generalComplete( const std::string& begin, const std::string& displayAs, const std::string& addBack, const std::string& addFront)219 { 220 if (this->input == NULL)221 return false; 207 bool ShellCompletion::generalComplete(std::string& input, 208 const std::string& begin, const std::string& displayAs, 209 const std::string& addBack, const std::string& addFront) 210 { 222 211 if (completionList.size() == 0) 223 212 return false; … … 257 246 adder.resize(addLength); 258 247 259 if (this->input) 248 input.resize(input.size()-inputLenght); 249 input += adder; 250 251 if (completionList.size() == 1) 260 252 { 261 this->input->removeCharacters(inputLenght); 262 this->input->addCharacters(adder); 263 264 if (completionList.size() == 1) 265 { 266 if ( addBack != "") 267 this->input->addCharacters(addBack); 268 this->input->addCharacter(' '); 269 } 253 if ( addBack != "") 254 input += addBack; 255 input += ' '; 270 256 } 271 257 } … … 301 287 302 288 /** 303 * searches for classes, which beginn with completionBegin289 * @brief searches for classes, which beginn with completionBegin 304 290 * @param inputList the List to parse through 305 291 * @param completionBegin the beginning string … … 330 316 331 317 /** 332 * deletes the Completion List.318 * @brief deletes the Completion List. 333 319 * 334 320 * This is done at the beginning of each completion-run -
trunk/src/lib/shell/shell_completion.h
r7225 r7343 39 39 40 40 public: 41 ShellCompletion( ShellInput* input = NULL);41 ShellCompletion(); 42 42 virtual ~ShellCompletion(); 43 43 44 bool autoComplete( ShellInput* input = NULL);44 bool autoComplete(std::string& input); 45 45 bool classComplete(const std::string& classBegin); 46 46 // long classMatch(const char* input, unsigned int* length); … … 51 51 bool aliasComplete(const std::string& aliasBegin); 52 52 53 bool generalComplete(const std::string& begin, const std::string& displayAs = "%s", 53 bool generalComplete(std::string& input, 54 const std::string& begin, const std::string& displayAs = "%s", 54 55 const std::string& addBack = "", const std::string& addFront = ""); 55 56 … … 62 63 private: 63 64 std::list<ShellC_Element> completionList; //!< A list of completions, that are io. 64 ShellInput* input; //!< the input this completion works on.65 65 }; 66 66 -
trunk/src/lib/shell/shell_input.cc
r7342 r7343 41 41 * this also generates a ShellCompletion automatically. 42 42 */ 43 ShellInput::ShellInput () : Text ("") 43 ShellInput::ShellInput () 44 : Text ("") 44 45 { 45 46 this->pressedKey = SDLK_FIRST; … … 66 67 evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN); 67 68 68 this->completion = new ShellCompletion(this); 69 } 70 71 /** 72 * standard deconstructor 73 */ 69 } 70 71 /** 72 * @brief standard deconstructor 73 */ 74 74 ShellInput::~ShellInput () 75 75 { 76 // delete what has to be deleted here 77 delete this->completion; 78 79 while (!this->history.empty()) 80 { 81 this->history.pop_front(); 82 } 83 } 84 85 /** 86 * sets the Repeate-delay and rate 76 } 77 78 /** 79 * @brief sets the Repeate-delay and rate 87 80 * @param repeatDelay the Delay it takes, to repeate a key 88 81 * @param repeatRate the rate to repeate a pressed key … … 95 88 96 89 /** 97 * deletes the InputLine90 * @brief deletes the InputLine 98 91 */ 99 92 void ShellInput::flush() … … 104 97 105 98 /** 106 * sets the entire text of the InputLine to text99 * @brief sets the entire text of the InputLine to text 107 100 * @param text the new Text to set as InputLine 108 101 */ … … 115 108 116 109 /** 117 * adds one character to the inputLine110 * @brief adds one character to the inputLine 118 111 * @param character the character to add to the inputLine 119 112 */ … … 131 124 132 125 /** 133 * adds multiple Characters to thr inputLine126 * @brief adds multiple Characters to thr inputLine 134 127 * @param characters a \\0 terminated char-array to add to the InputLine 135 128 */ … … 147 140 148 141 /** 149 * removes characterCount characters from the InputLine142 * @brief removes characterCount characters from the InputLine 150 143 * @param characterCount the count of Characters to remove from the input Line 151 144 */ … … 165 158 166 159 /** 167 * executes the command stored in the inputLine160 * @brief executes the command stored in the inputLine 168 161 * @return true if the command was commited successfully, false otherwise 169 162 */ … … 198 191 199 192 /** 200 * moves one entry up in the history.193 * @brief moves one entry up in the history. 201 194 */ 202 195 void ShellInput::historyMoveUp() … … 223 216 224 217 /** 225 * moves one entry down in the history218 * @brief moves one entry down in the history 226 219 */ 227 220 void ShellInput::historyMoveDown() … … 244 237 245 238 /** 246 * prints out some nice help about the Shell239 * @brief prints out some nice help about the Shell 247 240 */ 248 241 void ShellInput::help(const std::string& className, const std::string& functionName) … … 267 260 268 261 /** 269 * ticks the ShellInput262 * @brief ticks the ShellInput 270 263 * @param dt the time passed since the last update 271 264 */ … … 298 291 299 292 /** 300 * listens for some event293 * @brief listens for some event 301 294 * @param event the Event happened 302 295 */ … … 323 316 } 324 317 else if (event.type == SDLK_TAB) 325 this->completion->autoComplete(); 318 { 319 this->completion.autoComplete(this->inputLine); 320 this->setText(this->inputLine); 321 } 326 322 else if (event.type == SDLK_BACKSPACE) 327 323 { -
trunk/src/lib/shell/shell_input.h
r7221 r7343 12 12 #include "text.h" 13 13 #include "event_listener.h" 14 #include "shell_completion.h" 15 14 16 #include <list> 15 17 … … 54 56 private: 55 57 // HANDLING TEXT INPUT 56 ShellCompletion *completion; //!< The Completion Interface.58 ShellCompletion completion; //!< The Completion Interface. 57 59 58 60 std::string inputLine; //!< the Char-Array of the Buffer
Note: See TracChangeset
for help on using the changeset viewer.