- Timestamp:
- Nov 29, 2009, 10:43:43 PM (14 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.