Changeset 6417 for code/trunk/src/libraries/core/Shell.cc
- Timestamp:
- Dec 25, 2009, 10:23:58 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/Shell.cc
r6105 r6417 45 45 SetConsoleCommandShortcut(OutputHandler, debug); 46 46 47 Shell::Shell(const std::string& consoleName, bool bScrollable , bool bPrependOutputLevel)47 Shell::Shell(const std::string& consoleName, bool bScrollable) 48 48 : OutputListener(consoleName) 49 49 , inputBuffer_(new InputBuffer()) 50 50 , consoleName_(consoleName) 51 , bPrependOutputLevel_(bPrependOutputLevel)52 51 , bScrollable_(bScrollable) 53 52 { … … 63 62 this->configureInputBuffer(); 64 63 65 // Get a config file for the command history 66 this->commandHistoryConfigFileType_ = ConfigFileManager::getInstance().getNewConfigFileType(); 67 ConfigFileManager::getInstance().setFilename(this->commandHistoryConfigFileType_, "commandHistory.ini"); 68 69 // Use a stringstream object to buffer the output and get it line by line in update() 64 // Specify file for the command history 65 ConfigFileManager::getInstance().setFilename(ConfigFileType::CommandHistory, "commandHistory.ini"); 66 67 // Use a stringstream object to buffer the output 70 68 this->outputStream_ = &this->outputBuffer_; 71 69 … … 99 97 SetConfigValue(historyOffset_, 0) 100 98 .callback(this, &Shell::commandHistoryOffsetChanged); 101 SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>());99 setConfigValueGeneric(this, &commandHistory_, ConfigFileType::CommandHistory, "Shell", "commandHistory_", std::vector<std::string>()); 102 100 103 101 #ifdef ORXONOX_RELEASE … … 106 104 const unsigned int defaultLevel = 3; 107 105 #endif 108 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevel" + this->consoleName_, "OutputHandler", defaultLevel)106 setConfigValueGeneric(this, &softDebugLevel_, ConfigFileType::Settings, "OutputHandler", "softDebugLevel" + this->consoleName_, defaultLevel) 109 107 .description("The maximal level of debug output shown in the Shell"); 110 108 this->setSoftDebugLevel(this->softDebugLevel_); … … 163 161 164 162 for (unsigned int i = instance.historyOffset_; i < instance.commandHistory_.size(); ++i) 165 instance.addOutput Line(instance.commandHistory_[i], -1);163 instance.addOutput(instance.commandHistory_[i] + '\n', -1); 166 164 for (unsigned int i = 0; i < instance.historyOffset_; ++i) 167 instance.addOutput Line(instance.commandHistory_[i], -1);165 instance.addOutput(instance.commandHistory_[i] + '\n', -1); 168 166 } 169 167 */ … … 191 189 } 192 190 193 void Shell::addOutputLine(const std::string& line, int level) 194 { 195 // Make sure we really only have one line per line (no new lines!) 196 SubString lines(line, '\n'); 197 for (unsigned i = 0; i < lines.size(); ++i) 198 { 199 if (level <= this->softDebugLevel_) 200 this->outputLines_.push_front(lines[i]); 201 this->updateListeners<&ShellListener::lineAdded>(); 202 } 191 void Shell::addOutput(const std::string& text, LineType type) 192 { 193 this->outputBuffer_ << text; 194 this->outputChanged(type); 203 195 } 204 196 … … 214 206 } 215 207 216 std::list<std::string>::const_iterator Shell::getNewestLineIterator() const208 Shell::LineList::const_iterator Shell::getNewestLineIterator() const 217 209 { 218 210 if (this->scrollPosition_) … … 222 214 } 223 215 224 std::list<std::string>::const_iterator Shell::getEndIterator() const216 Shell::LineList::const_iterator Shell::getEndIterator() const 225 217 { 226 218 return this->outputLines_.end(); … … 234 226 } 235 227 236 std::stringShell::getFromHistory() const228 const std::string& Shell::getFromHistory() const 237 229 { 238 230 unsigned int index = mod(static_cast<int>(this->historyOffset_) - static_cast<int>(this->historyPosition_), this->maxHistoryLength_); … … 240 232 return this->commandHistory_[index]; 241 233 else 242 return "";243 } 244 245 void Shell::outputChanged(int l evel)234 return BLANKSTRING; 235 } 236 237 void Shell::outputChanged(int lineType) 246 238 { 247 239 bool newline = false; … … 259 251 newline = (!eof && !fail); 260 252 261 if (!newline && output == "")253 if (!newline && output.empty()) 262 254 break; 263 255 264 256 if (this->bFinishedLastLine_) 265 257 { 266 if (this->bPrependOutputLevel_) 267 output.insert(0, 1, static_cast<char>(level)); 268 269 this->outputLines_.push_front(output); 258 this->outputLines_.push_front(std::make_pair(output, static_cast<LineType>(lineType))); 270 259 271 260 if (this->scrollPosition_) … … 277 266 278 267 if (!this->scrollPosition_) 279 {280 268 this->updateListeners<&ShellListener::lineAdded>(); 281 }282 269 } 283 270 else 284 271 { 285 (*this->outputLines_.begin())+= output;272 this->outputLines_.front().first += output; 286 273 this->bFinishedLastLine_ = newline; 287 274 this->updateListeners<&ShellListener::onlyLastLineChanged>(); 288 275 } 276 this->bFinishedLastLine_ = newline; 289 277 290 278 } while (newline); … … 320 308 321 309 if (!CommandExecutor::execute(this->inputBuffer_->get())) 322 this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1); 310 { 311 this->outputBuffer_ << "Error: Can't execute \"" << this->inputBuffer_->get() << "\"." << std::endl; 312 this->outputChanged(Error); 313 } 323 314 324 315 this->clearInput(); … … 328 319 { 329 320 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 330 this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1); 321 this->outputBuffer_ << CommandExecutor::hint(this->inputBuffer_->get()) << std::endl; 322 this->outputChanged(Hint); 331 323 332 324 this->inputChanged(); … … 408 400 return; 409 401 unsigned int cursorPosition = this->getCursorPosition(); 410 std::stringinput_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until the cursor position402 const std::string& input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until the cursor position 411 403 for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++) 412 404 { … … 426 418 return; 427 419 unsigned int cursorPosition = this->getCursorPosition(); 428 std::stringinput_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning420 const std::string& input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning 429 421 for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--) 430 422 {
Note: See TracChangeset
for help on using the changeset viewer.