Changeset 5994 for code/branches/console/src/libraries/core/Shell.cc
- Timestamp:
- Oct 27, 2009, 2:47:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/Shell.cc
r5986 r5994 51 51 52 52 Shell::Shell() 53 { 54 int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell); 55 Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1); 56 53 : OutputListener("shell") 54 { 57 55 RegisterRootObject(Shell); 58 56 … … 69 67 this->configureInputBuffer(); 70 68 71 this->outputBuffer_.registerListener(this);72 OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);73 74 69 // Get a config file for the command history 75 70 this->commandHistoryConfigFileType_ = ConfigFileManager::getInstance().getNewConfigFileType(); 76 71 ConfigFileManager::getInstance().setFilename(this->commandHistoryConfigFileType_, "commandHistory.ini"); 77 72 73 // Use a stringstream object to buffer the output and get it line by line in update() 74 this->outputStream_ = &this->outputBuffer_; 75 78 76 this->setConfigValues(); 79 77 80 Core::setSoftDebugLevel(OutputHandler::LD_Shell, level); 78 // Get the previous output and add it to the Shell 79 for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin(); 80 it != OutputHandler::getInstance().getOutputVectorEnd(); ++it) 81 this->addLine(it->second, it->first); 82 83 // Register the shell as output listener 84 OutputHandler::getInstance().registerOutputListener(this); 81 85 } 82 86 83 87 Shell::~Shell() 84 88 { 85 OutputHandler::getOutStream().setOutputBuffer(0); 86 if (this->inputBuffer_) 87 this->inputBuffer_->destroy(); 89 OutputHandler::getInstance().unregisterOutputListener(this); 90 this->inputBuffer_->destroy(); 88 91 } 89 92 90 93 void Shell::setConfigValues() 91 94 { 92 SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, 100)95 SetConfigValueGeneric(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100) 93 96 .callback(this, &Shell::commandHistoryLengthChanged); 94 SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, 0)97 SetConfigValueGeneric(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0) 95 98 .callback(this, &Shell::commandHistoryOffsetChanged); 96 99 SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>()); 100 101 #ifdef ORXONOX_RELEASE 102 const unsigned int defaultLevel = 1; 103 #else 104 const unsigned int defaultLevel = 3; 105 #endif 106 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevelShell", "OutputHandler", defaultLevel) 107 .description("The maximal level of debug output shown in the Shell"); 108 OutputHandler::getInstance().setSoftDebugLevel("shell", this->softDebugLevel_); 97 109 } 98 110 … … 182 194 void Shell::addLine(const std::string& line, int level) 183 195 { 184 int original_level = OutputHandler::getOutStream().getOutputLevel(); 185 OutputHandler::getOutStream().setOutputLevel(level); 186 187 if (!this->finishedLastLine_) 188 this->outputBuffer_ << std::endl; 189 190 this->outputBuffer_ << line << std::endl; 191 OutputHandler::getOutStream().setOutputLevel(original_level); 196 if (level <= this->softDebugLevel_) 197 this->lines_.push_front(line); 198 this->updateListeners<&ShellListener::lineAdded>(); 192 199 } 193 200 … … 238 245 do 239 246 { 240 newline = this->outputBuffer_.getLine(&output); 247 std::getline(this->outputBuffer_, output); 248 249 bool eof = this->outputBuffer_.eof(); 250 bool fail = this->outputBuffer_.fail(); 251 if (eof) 252 this->outputBuffer_.flush(); 253 if (eof || fail) 254 this->outputBuffer_.clear(); 255 newline = (!eof && !fail); 241 256 242 257 if (!newline && output == "") … … 246 261 { 247 262 if (this->bAddOutputLevel_) 248 output.insert(0, 1, static_cast<char>(OutputHandler::get OutStream().getOutputLevel()));249 250 this->lines_. insert(this->lines_.begin(),output);263 output.insert(0, 1, static_cast<char>(OutputHandler::getInstance().getOutputLevel())); 264 265 this->lines_.push_front(output); 251 266 252 267 if (this->scrollPosition_) … … 365 380 return; 366 381 unsigned int cursorPosition = this->getCursorPosition(); 367 std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position368 for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)369 { 370 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive382 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position 383 for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++) 384 { 385 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // search case insensitive 371 386 { 372 387 this->historyPosition_ = newPos; 373 388 this->inputBuffer_->set(this->getFromHistory()); 374 this->setCursorPosition( cursorPosition);389 this->setCursorPosition(cursorPosition); 375 390 return; 376 391 } … … 383 398 return; 384 399 unsigned int cursorPosition = this->getCursorPosition(); 385 std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$386 for (unsigned int newPos = this->historyPosition_ -1; newPos>0; newPos--)387 { 388 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$400 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$ 401 for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--) 402 { 403 if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) // sear$ 389 404 { 390 405 this->historyPosition_ = newPos; 391 406 this->inputBuffer_->set(this->getFromHistory()); 392 this->setCursorPosition( cursorPosition);407 this->setCursorPosition(cursorPosition); 393 408 return; 394 409 }
Note: See TracChangeset
for help on using the changeset viewer.