Changeset 1446 for code/branches/network/src/core/Shell.cc
- Timestamp:
- May 28, 2008, 5:30:11 AM (16 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/Shell.cc
r1445 r1446 33 33 #include "CoreSettings.h" 34 34 #include "ConsoleCommand.h" 35 #include "InputManager.h" 35 36 36 37 #define SHELL_UPDATE_LISTENERS(function) \ … … 56 57 this->clearLines(); 57 58 58 this->inputBuffer_.registerListener(this, &Shell::inputChanged, true); 59 this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false); 60 this->inputBuffer_.registerListener(this, &Shell::hintandcomplete, '\t', true); 61 this->inputBuffer_.registerListener(this, &Shell::backspace, '\b', true); 62 this->inputBuffer_.registerListener(this, &Shell::deletechar, OIS::KC_DELETE); 63 this->inputBuffer_.registerListener(this, &Shell::exit, (char)27, true); 64 this->inputBuffer_.registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT); 65 this->inputBuffer_.registerListener(this, &Shell::cursor_left, OIS::KC_LEFT); 66 this->inputBuffer_.registerListener(this, &Shell::cursor_end, OIS::KC_END); 67 this->inputBuffer_.registerListener(this, &Shell::cursor_home, OIS::KC_HOME); 68 this->inputBuffer_.registerListener(this, &Shell::history_up, OIS::KC_UP); 69 this->inputBuffer_.registerListener(this, &Shell::history_down, OIS::KC_DOWN); 70 this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 71 this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 59 this->inputBuffer_ = 0; 60 this->setInputBuffer(new InputBuffer()); 72 61 73 62 this->outputBuffer_.registerListener(this); … … 108 97 } 109 98 99 void Shell::setInputBuffer(InputBuffer* buffer) 100 { 101 if (this->inputBuffer_) 102 { 103 this->inputBuffer_->unregisterListener(this); 104 delete this->inputBuffer_; 105 } 106 107 this->inputBuffer_ = buffer; 108 this->inputBuffer_->registerListener(this, &Shell::inputChanged, true); 109 this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false); 110 this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true); 111 this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true); 112 this->inputBuffer_->registerListener(this, &Shell::deletechar, OIS::KC_DELETE); 113 this->inputBuffer_->registerListener(this, &Shell::exit, (char)27, true); 114 this->inputBuffer_->registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT); 115 this->inputBuffer_->registerListener(this, &Shell::cursor_left, OIS::KC_LEFT); 116 this->inputBuffer_->registerListener(this, &Shell::cursor_end, OIS::KC_END); 117 this->inputBuffer_->registerListener(this, &Shell::cursor_home, OIS::KC_HOME); 118 this->inputBuffer_->registerListener(this, &Shell::history_up, OIS::KC_UP); 119 this->inputBuffer_->registerListener(this, &Shell::history_down, OIS::KC_DOWN); 120 this->inputBuffer_->registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 121 this->inputBuffer_->registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 122 } 123 110 124 void Shell::clearShell() 111 125 { … … 141 155 void Shell::setCursorPosition(unsigned int cursor) 142 156 { 143 this->inputBuffer_ .setCursorPosition(cursor);157 this->inputBuffer_->setCursorPosition(cursor); 144 158 SHELL_UPDATE_LISTENERS(cursorChanged); 145 159 } … … 147 161 void Shell::setInput(const std::string& input) 148 162 { 149 this->inputBuffer_ .set(input);163 this->inputBuffer_->set(input); 150 164 this->inputChanged(); 151 165 } … … 251 265 void Shell::execute() 252 266 { 253 this->addToHistory(this->inputBuffer_ .get());254 this->addLine(this->inputBuffer_ .get(), 0);255 256 if (!CommandExecutor::execute(this->inputBuffer_ .get()))257 this->addLine("Error: Can't execute \"" + this->inputBuffer_ .get() + "\".", 1);267 this->addToHistory(this->inputBuffer_->get()); 268 this->addLine(this->inputBuffer_->get(), 0); 269 270 if (!CommandExecutor::execute(this->inputBuffer_->get())) 271 this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1); 258 272 259 273 this->clear(); … … 262 276 void Shell::hintandcomplete() 263 277 { 264 this->inputBuffer_ .set(CommandExecutor::complete(this->inputBuffer_.get()));265 this->addLine(CommandExecutor::hint(this->inputBuffer_ .get()), -1);278 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 279 this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1); 266 280 267 281 this->inputChanged(); … … 270 284 void Shell::backspace() 271 285 { 272 this->inputBuffer_ .removeBehindCursor();286 this->inputBuffer_->removeBehindCursor(); 273 287 SHELL_UPDATE_LISTENERS(inputChanged); 274 288 SHELL_UPDATE_LISTENERS(cursorChanged); … … 277 291 void Shell::deletechar() 278 292 { 279 this->inputBuffer_ .removeAtCursor();293 this->inputBuffer_->removeAtCursor(); 280 294 SHELL_UPDATE_LISTENERS(inputChanged); 281 295 } … … 283 297 void Shell::clear() 284 298 { 285 this->inputBuffer_ .clear();299 this->inputBuffer_->clear(); 286 300 this->historyPosition_ = 0; 287 301 SHELL_UPDATE_LISTENERS(inputChanged); … … 291 305 void Shell::cursor_right() 292 306 { 293 this->inputBuffer_ .increaseCursor();307 this->inputBuffer_->increaseCursor(); 294 308 SHELL_UPDATE_LISTENERS(cursorChanged); 295 309 } … … 297 311 void Shell::cursor_left() 298 312 { 299 this->inputBuffer_ .decreaseCursor();313 this->inputBuffer_->decreaseCursor(); 300 314 SHELL_UPDATE_LISTENERS(cursorChanged); 301 315 } … … 303 317 void Shell::cursor_end() 304 318 { 305 this->inputBuffer_ .setCursorToEnd();319 this->inputBuffer_->setCursorToEnd(); 306 320 SHELL_UPDATE_LISTENERS(cursorChanged); 307 321 } … … 309 323 void Shell::cursor_home() 310 324 { 311 this->inputBuffer_ .setCursorToBegin();325 this->inputBuffer_->setCursorToBegin(); 312 326 SHELL_UPDATE_LISTENERS(cursorChanged); 313 327 } … … 318 332 { 319 333 this->historyPosition_++; 320 this->inputBuffer_ .set(this->getFromHistory());334 this->inputBuffer_->set(this->getFromHistory()); 321 335 } 322 336 } … … 327 341 { 328 342 this->historyPosition_--; 329 this->inputBuffer_ .set(this->getFromHistory());343 this->inputBuffer_->set(this->getFromHistory()); 330 344 } 331 345 } … … 355 369 void Shell::exit() 356 370 { 357 if (this->inputBuffer_ .getSize() > 0)371 if (this->inputBuffer_->getSize() > 0) 358 372 { 359 373 this->clear();
Note: See TracChangeset
for help on using the changeset viewer.