Changeset 6180
- Timestamp:
- Nov 29, 2009, 10:43:43 PM (15 years ago)
- Location:
- code/branches/presentation2/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/IOConsole.cc
r6179 r6180 45 45 IOConsole* IOConsole::singletonPtr_s = NULL; 46 46 47 //! Extracts the log level associated to a string (first character)48 int IOConsole::extractLogLevel(std::string* text)49 {50 // Handle line colouring by inspecting the first letter51 char level = 0;52 if (!text->empty())53 {54 level = (*text)[0];55 if (level == -1 || (level >= 1 && level <= 6))56 {57 *text = text->substr(1);58 if (level != -1)59 return level;60 }61 }62 return 0;63 }64 65 47 // ############################### 66 48 // ### ShellListener methods ### … … 78 60 void IOConsole::executed() 79 61 { 80 this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput() );62 this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput(), Shell::Command); 81 63 } 82 64 … … 109 91 110 92 IOConsole::IOConsole() 111 : shell_(new Shell("IOConsole", false , true))93 : shell_(new Shell("IOConsole", false)) 112 94 , buffer_(shell_->getInputBuffer()) 113 95 , cout_(std::cout.rdbuf()) … … 280 262 if (!this->origCout_.str().empty()) 281 263 { 282 this->shell_->addOutputLine(this->origCout_.str() );264 this->shell_->addOutputLine(this->origCout_.str(), Shell::None); 283 265 this->origCout_.str(""); 284 266 } 285 267 } 286 268 287 void IOConsole::printOutputLine(const std::string& text) 288 { 289 std::string output = text; 290 /*int level =*/ this->extractLogLevel(&output); 291 269 void IOConsole::printOutputLine(const std::string& text, Shell::LineType type) 270 { 292 271 /* 293 272 // Colour line 294 switch ( level)295 { 296 case -1:this->cout_ << "\033[37m"; break;297 case 1:this->cout_ << "\033[91m"; break;298 case 2: this->cout_ << "\033[31m"; break;299 case 3:this->cout_ << "\033[34m"; break;300 case 4:this->cout_ << "\033[36m"; break;301 case 5: this->cout_ << "\033[35m"; break;302 case 6:this->cout_ << "\033[37m"; break;273 switch (type) 274 { 275 case Shell::None: this->cout_ << "\033[37m"; break; 276 case Shell::Error: this->cout_ << "\033[91m"; break; 277 case Shell::Warning: this->cout_ << "\033[31m"; break; 278 case Shell::Info: this->cout_ << "\033[34m"; break; 279 case Shell::Debug: this->cout_ << "\033[36m"; break; 280 case Shell::Verbose: this->cout_ << "\033[35m"; break; 281 case Shell::Ultra: this->cout_ << "\033[37m"; break; 303 282 default: break; 304 283 } … … 306 285 307 286 // Print output line 308 this->cout_ << output;287 this->cout_ << text; 309 288 310 289 // Reset colour to white … … 419 398 this->cout_ << "\033[K"; 420 399 // Reprint the last output line 421 this->printOutputLine( *(this->shell_->getNewestLineIterator()));400 this->printOutputLine(this->shell_->getNewestLineIterator()->first); 422 401 // Restore cursor 423 402 this->cout_ << "\033[u"; … … 428 407 void IOConsole::lineAdded() 429 408 { 430 int newLines = this->shell_->getNewestLineIterator()-> size() / this->terminalWidth_ + 1;409 int newLines = this->shell_->getNewestLineIterator()->first.size() / this->terminalWidth_ + 1; 431 410 // Create new lines by scrolling the screen 432 411 this->cout_ << "\033[" << newLines << 'S'; … … 437 416 // Print the new output lines 438 417 for (int i = 0; i < newLines; ++i) 439 this->printOutputLine(this->shell_->getNewestLineIterator()-> substr(i*this->terminalWidth_, this->terminalWidth_));418 this->printOutputLine(this->shell_->getNewestLineIterator()->first.substr(i*this->terminalWidth_, this->terminalWidth_)); 440 419 // Move cursor down 441 420 this->cout_ << "\033[1B\033[1G"; … … 472 451 //! Redirects std::cout, creates the corresponding Shell and changes the terminal mode 473 452 IOConsole::IOConsole() 474 : shell_(new Shell("IOConsole", false , true))453 : shell_(new Shell("IOConsole", false)) 475 454 , buffer_(shell_->getInputBuffer()) 476 455 , cout_(std::cout.rdbuf()) … … 613 592 if (!this->origCout_.str().empty()) 614 593 { 615 this->shell_->addOutputLine(this->origCout_.str() );594 this->shell_->addOutputLine(this->origCout_.str(), Shell::None); 616 595 this->origCout_.str(""); 617 596 } … … 619 598 620 599 //! Prints output text. Similar to writeText, but sets the colour according to the output level 621 void IOConsole::printOutputLine(const std::string& text, const COORD& pos) 622 { 623 std::string output = text; 624 int level = this->extractLogLevel(&output); 625 600 void IOConsole::printOutputLine(const std::string& text, Shell::LineType type, const COORD& pos) 601 { 626 602 // Colour line 627 603 WORD colour = 0; 628 switch (level) 629 { 630 case 1: colour = FOREGROUND_INTENSITY | FOREGROUND_RED ; break; 631 case 2: colour = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED ; break; 632 case 3: colour = FOREGROUND_INTENSITY ; break; 633 case 4: colour = FOREGROUND_INTENSITY ; break; 634 default: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ; break; 604 switch (type) 605 { 606 case Shell::Error: colour = FOREGROUND_INTENSITY | FOREGROUND_RED; break; 607 case Shell::Warning: colour = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED; break; 608 case Shell::Info: 609 case Shell::Debug: 610 case Shell::Verbose: 611 case Shell::Ultra: colour = FOREGROUND_INTENSITY ; break; 612 case Shell::Command: colour = FOREGROUND_GREEN | FOREGROUND_BLUE; break; 613 case Shell::Hint: colour = FOREGROUND_GREEN | FOREGROUND_RED ; break; 614 default: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; break; 635 615 } 636 616 637 617 // Print output line 638 this->writeText( output, pos, colour);618 this->writeText(text, pos, colour); 639 619 } 640 620 … … 783 763 void IOConsole::onlyLastLineChanged() 784 764 { 785 int newLineHeight = 1 + this->shell_->getNewestLineIterator()-> size() / this->terminalWidth_;765 int newLineHeight = 1 + this->shell_->getNewestLineIterator()->first.size() / this->terminalWidth_; 786 766 // Compute the number of new lines needed 787 767 int newLines = newLineHeight - this->lastOutputLineHeight_; … … 790 770 if (newLines > 0) // newLines < 0 is assumed impossible 791 771 this->createNewOutputLines(newLines); 792 this->printOutputLine(*(this->shell_->getNewestLineIterator()), makeCOORD(0, this->inputLineRow_ - newLineHeight)); 772 Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator(); 773 this->printOutputLine(it->first, it->second, makeCOORD(0, this->inputLineRow_ - newLineHeight)); 793 774 } 794 775 … … 796 777 void IOConsole::lineAdded() 797 778 { 779 Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator(); 798 780 // Scroll console 799 this->lastOutputLineHeight_ = 1 + this->shell_->getNewestLineIterator()->size() / this->terminalWidth_;781 this->lastOutputLineHeight_ = 1 + it->first.size() / this->terminalWidth_; 800 782 this->createNewOutputLines(this->lastOutputLineHeight_); 801 783 // Write the text 802 784 COORD pos = {0, this->inputLineRow_ - this->lastOutputLineHeight_}; 803 this->printOutputLine( *(this->shell_->getNewestLineIterator()), pos);785 this->printOutputLine(it->first, it->second, pos); 804 786 } 805 787 } -
code/branches/presentation2/src/libraries/core/IOConsole.h
r6179 r6180 87 87 bool willPrintStatusLines(); 88 88 void printInputLine(); 89 void printOutputLine(const std::string& line );89 void printOutputLine(const std::string& line, Shell::LineType type); 90 90 static void resetTerminalMode(); 91 91 … … 102 102 void writeText(const std::string& text, const COORD& pos, WORD attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); 103 103 void createNewOutputLines(int lines); 104 void printOutputLine(const std::string& line, const COORD& pos);104 void printOutputLine(const std::string& line, Shell::LineType type, const COORD& pos); 105 105 106 106 static inline COORD makeCOORD(int x, int y) -
code/branches/presentation2/src/libraries/core/Shell.cc
r6139 r6180 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 { … … 191 190 } 192 191 193 void Shell::addOutputLine(const std::string& line, int level)192 void Shell::addOutputLine(const std::string& line, LineType type) 194 193 { 195 194 // Make sure we really only have one line per line (no new lines!) … … 197 196 for (unsigned i = 0; i < lines.size(); ++i) 198 197 { 199 if (level <= this->softDebugLevel_) 200 this->outputLines_.push_front(lines[i]); 198 this->outputLines_.push_front(std::make_pair(lines[i], type)); 201 199 this->updateListeners<&ShellListener::lineAdded>(); 202 200 } … … 214 212 } 215 213 216 std::list<std::string>::const_iterator Shell::getNewestLineIterator() const214 Shell::LineList::const_iterator Shell::getNewestLineIterator() const 217 215 { 218 216 if (this->scrollPosition_) … … 222 220 } 223 221 224 std::list<std::string>::const_iterator Shell::getEndIterator() const222 Shell::LineList::const_iterator Shell::getEndIterator() const 225 223 { 226 224 return this->outputLines_.end(); … … 264 262 if (this->bFinishedLastLine_) 265 263 { 266 if (this->bPrependOutputLevel_) 267 { 268 if (level == 0) 269 output.insert(0, 1, static_cast<char>(-1)); 270 else 271 output.insert(0, 1, static_cast<char>(level)); 272 } 273 274 this->outputLines_.push_front(output); 264 this->outputLines_.push_front(std::make_pair(output, static_cast<LineType>(level))); 275 265 276 266 if (this->scrollPosition_) … … 288 278 else 289 279 { 290 (*this->outputLines_.begin())+= output;280 this->outputLines_.front().first += output; 291 281 this->bFinishedLastLine_ = newline; 292 282 this->updateListeners<&ShellListener::onlyLastLineChanged>(); … … 325 315 326 316 if (!CommandExecutor::execute(this->inputBuffer_->get())) 327 this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);317 this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", Error); 328 318 329 319 this->clearInput(); … … 333 323 { 334 324 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 335 this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);325 this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), Hint); 336 326 337 327 this->inputChanged(); -
code/branches/presentation2/src/libraries/core/Shell.h
r6105 r6180 65 65 { 66 66 public: 67 Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false); 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 }; 80 81 Shell(const std::string& consoleName, bool bScrollable); 68 82 ~Shell(); 69 83 … … 85 99 { return this->inputBuffer_->get(); } 86 100 87 std::list<std::string>::const_iterator getNewestLineIterator() const; 88 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; 89 104 90 void addOutputLine(const std::string& line, int level = 0);105 void addOutputLine(const std::string& line, LineType type = None); 91 106 void clearOutput(); 92 107 … … 139 154 std::stringstream outputBuffer_; 140 155 bool bFinishedLastLine_; 141 std::list<std::string>outputLines_;142 std::list<std::string>::const_iteratorscrollIterator_;156 LineList outputLines_; 157 LineList::const_iterator scrollIterator_; 143 158 unsigned int scrollPosition_; 144 159 unsigned int historyPosition_; … … 147 162 std::string promptPrefix_; 148 163 const std::string consoleName_; 149 const bool bPrependOutputLevel_;150 164 const bool bScrollable_; 151 165 -
code/branches/presentation2/src/orxonox/overlays/InGameConsole.cc
r6139 r6180 68 68 */ 69 69 InGameConsole::InGameConsole() 70 : shell_(new Shell("InGameConsole", true , true))70 : shell_(new Shell("InGameConsole", true)) 71 71 , consoleOverlay_(0) 72 72 , consoleOverlayContainer_(0) … … 268 268 void InGameConsole::linesChanged() 269 269 { 270 std::list<std::string>::const_iterator it = this->shell_->getNewestLineIterator();270 Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator(); 271 271 int max = 0; 272 272 for (int i = 1; i < LINES; ++i) … … 282 282 283 283 for (int i = LINES - 1; i > max; --i) 284 this->print("", i, true);284 this->print("", Shell::None, i, true); 285 285 286 286 for (int i = max; i >= 1; --i) 287 287 { 288 288 --it; 289 this->print( *it, i, true);289 this->print(it->first, it->second, i, true); 290 290 } 291 291 } … … 297 297 { 298 298 if (LINES > 1) 299 this->print( *this->shell_->getNewestLineIterator(), 1);299 this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1); 300 300 } 301 301 … … 316 316 { 317 317 if (LINES > 0) 318 this->print(this->shell_->getInput(), 0);318 this->print(this->shell_->getInput(), Shell::Input, 0); 319 319 320 320 if (this->shell_->getInput() == "" || this->shell_->getInput().size() == 0) … … 340 340 void InGameConsole::executed() 341 341 { 342 this->shell_->addOutputLine(this->shell_->getInput() );342 this->shell_->addOutputLine(this->shell_->getInput(), Shell::Command); 343 343 } 344 344 … … 456 456 @param s String to be printed 457 457 */ 458 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 459 { 460 char level = 0; 461 if (text.size() > 0) 462 level = text[0]; 463 458 void InGameConsole::print(const std::string& text, Shell::LineType type, int index, bool alwaysShift) 459 { 464 460 std::string output = text; 465 466 if (level >= -1 && level <= 5)467 output.erase(0, 1);468 469 461 if (LINES > index) 470 462 { 471 this->colourLine( level, index);463 this->colourLine(type, index); 472 464 473 465 if (index > 0) … … 482 474 if (linesUsed > numLinesShifted_ || alwaysShift) 483 475 this->shiftLines(); 484 this->colourLine( level, index);476 this->colourLine(type, index); 485 477 } 486 478 this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output)); … … 559 551 } 560 552 561 void InGameConsole::colourLine(int colourcode, int index) 562 { 563 if (colourcode == -1) 564 { 565 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 566 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 567 } 568 else if (colourcode == 1) 569 { 570 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 571 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 572 } 573 else if (colourcode == 2) 574 { 575 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 576 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 577 } 578 else if (colourcode == 3) 579 { 580 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 581 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 582 } 583 else if (colourcode == 4) 584 { 585 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 586 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 587 } 588 else if (colourcode == 5) 589 { 590 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 591 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 592 } 593 else 594 { 595 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 596 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 597 } 553 void InGameConsole::colourLine(Shell::LineType type, int index) 554 { 555 ColourValue colourTop, colourBottom; 556 switch (type) 557 { 558 case Shell::Error: colourTop = ColourValue(0.95, 0.25, 0.25, 1.00); 559 colourBottom = ColourValue(1.00, 0.50, 0.50, 1.00); break; 560 561 case Shell::Warning: colourTop = ColourValue(0.95, 0.50, 0.20, 1.00); 562 colourBottom = ColourValue(1.00, 0.70, 0.50, 1.00); break; 563 564 case Shell::Info: colourTop = ColourValue(0.50, 0.50, 0.95, 1.00); 565 colourBottom = ColourValue(0.80, 0.80, 1.00, 1.00); break; 566 567 case Shell::Debug: colourTop = ColourValue(0.65, 0.48, 0.44, 1.00); 568 colourBottom = ColourValue(1.00, 0.90, 0.90, 1.00); break; 569 570 case Shell::Verbose: colourTop = ColourValue(0.40, 0.20, 0.40, 1.00); 571 colourBottom = ColourValue(0.80, 0.60, 0.80, 1.00); break; 572 573 case Shell::Ultra: colourTop = ColourValue(0.21, 0.69, 0.21, 1.00); 574 colourBottom = ColourValue(0.80, 1.00, 0.80, 1.00); break; 575 576 case Shell::Command: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00); 577 colourBottom = ColourValue(0.90, 0.90, 0.90, 0.90); break; 578 579 case Shell::Hint: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00); 580 colourBottom = ColourValue(0.90, 0.90, 0.90, 1.00); break; 581 582 default: colourTop = ColourValue(0.90, 0.90, 0.90, 1.00); 583 colourBottom = ColourValue(1.00, 1.00, 1.00, 1.00); break; 584 } 585 586 this->consoleOverlayTextAreas_[index]->setColourTop (colourTop); 587 this->consoleOverlayTextAreas_[index]->setColourBottom(colourBottom); 598 588 } 599 589 -
code/branches/presentation2/src/orxonox/overlays/InGameConsole.h
r6105 r6180 72 72 73 73 void shiftLines(); 74 void colourLine( int colourcode, int index);74 void colourLine(Shell::LineType type, int index); 75 75 void setCursorPosition(unsigned int pos); 76 void print(const std::string& text, int index, bool alwaysShift = false);76 void print(const std::string& text, Shell::LineType type, int index, bool alwaysShift = false); 77 77 78 78 void windowResized(unsigned int newWidth, unsigned int newHeight);
Note: See TracChangeset
for help on using the changeset viewer.