Changeset 6037
- Timestamp:
- Nov 5, 2009, 1:31:31 PM (15 years ago)
- Location:
- code/branches/console/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/IOConsole.cc
r6015 r6037 74 74 { 75 75 // Method only gets called upon start to draw all the lines 76 // or when scrolling. But scrolling is disable and the output76 // or when scrolling. But scrolling is disabled and the output 77 77 // is already in std::cout when we start the IOConsole 78 78 } … … 82 82 { 83 83 this->printInputLine(); 84 std::cout.flush();84 this->cout_.flush(); 85 85 } 86 86 … … 89 89 { 90 90 this->printInputLine(); 91 std::cout.flush();91 this->cout_.flush(); 92 92 } 93 93 … … 112 112 #include <termios.h> 113 113 #include <sys/ioctl.h> 114 #include <sys/stat.h>115 114 116 115 namespace orxonox … … 129 128 : shell_(new Shell("IOConsole", false, true)) 130 129 , buffer_(shell_->getInputBuffer()) 131 , originalTerminalSettings_(new termios())130 , cout_(std::cout.rdbuf()) 132 131 , bStatusPrinted_(false) 133 132 , promptString_("orxonox # ") 133 , originalTerminalSettings_(new termios()) 134 134 { 135 135 this->setTerminalMode(); … … 146 146 // Disable standard std::cout logging 147 147 OutputHandler::getInstance().disableCout(); 148 // Redirect std::cout to an ostringstream 149 // (Other part is in the initialiser list) 150 std::cout.rdbuf(this->origCout_.rdbuf()); 151 152 // Make sure we make way for the status lines 153 this->update(Game::getInstance().getGameClock()); 148 154 } 149 155 150 156 IOConsole::~IOConsole() 151 157 { 158 // Empty all buffers 159 this->update(Game::getInstance().getGameClock()); 152 160 // Goto last line and create a new one 153 161 if (this->bStatusPrinted_) 154 std::cout<< "\033[" << this->statusLineWidths_.size() << 'E';155 std::cout<< std::endl;162 this->cout_ << "\033[" << this->statusLineWidths_.size() << 'E'; 163 this->cout_ << std::endl; 156 164 157 165 resetTerminalMode(); … … 159 167 this->shell_->destroy(); 160 168 169 // Restore this->cout_ redirection 170 std::cout.rdbuf(this->cout_.rdbuf()); 161 171 // Enable standard std::cout logging again 162 172 OutputHandler::getInstance().enableCout(); … … 250 260 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0)); 251 261 262 // Process output written to std::cout 263 if (!this->origCout_.str().empty()) 264 { 265 this->shell_->addOutputLine(this->origCout_.str()); 266 this->origCout_.str(""); 267 } 268 252 269 // Determine terminal width and height 253 270 this->lastTerminalWidth_ = this->terminalWidth_; … … 261 278 // but that line might very well be the last 262 279 int newLines = std::min((int)this->statusLineWidths_.size(), -heightDiff); 263 std::cout<< std::string(newLines, '\n');280 this->cout_ << std::string(newLines, '\n'); 264 281 // Move cursor up again 265 std::cout<< "\033[" << newLines << 'F';282 this->cout_ << "\033[" << newLines << 'F'; 266 283 } 267 284 … … 269 286 { 270 287 // Print new lines to make way for status lines 271 std::cout<< std::string(this->statusLineWidths_.size(), '\n');288 this->cout_ << std::string(this->statusLineWidths_.size(), '\n'); 272 289 // Move cursor up again 273 std::cout<< "\033[" << this->statusLineWidths_.size() << 'F';290 this->cout_ << "\033[" << this->statusLineWidths_.size() << 'F'; 274 291 this->bStatusPrinted_ = true; 275 292 } 276 293 // Erase status and input lines 277 std::cout<< "\033[1G\033[J";294 this->cout_ << "\033[1G\033[J"; 278 295 this->printInputLine(); 279 296 this->printStatusLines(); 280 std::cout.flush();297 this->cout_.flush(); 281 298 } 282 299 … … 284 301 { 285 302 std::string output = text; 303 /* 286 304 int level = this->extractLogLevel(&output); 287 305 288 306 // Colour line 289 /*290 307 switch (level) 291 308 { 292 case -1: std::cout<< "\033[37m"; break;293 case 1: std::cout<< "\033[91m"; break;294 case 2: std::cout<< "\033[31m"; break;295 case 3: std::cout<< "\033[34m"; break;296 case 4: std::cout<< "\033[36m"; break;297 case 5: std::cout<< "\033[35m"; break;298 case 6: std::cout<< "\033[37m"; break;309 case -1: this->cout_ << "\033[37m"; break; 310 case 1: this->cout_ << "\033[91m"; break; 311 case 2: this->cout_ << "\033[31m"; break; 312 case 3: this->cout_ << "\033[34m"; break; 313 case 4: this->cout_ << "\033[36m"; break; 314 case 5: this->cout_ << "\033[35m"; break; 315 case 6: this->cout_ << "\033[37m"; break; 299 316 default: break; 300 317 } … … 302 319 303 320 // Print output line 304 std::cout<< output;321 this->cout_ << output; 305 322 306 323 // Reset colour to white 307 // std::cout<< "\033[37m";324 // this->cout_ << "\033[37m"; 308 325 } 309 326 … … 311 328 { 312 329 // Set cursor to the beginning of the line and erase the line 313 std::cout<< "\033[1G\033[K";330 this->cout_ << "\033[1G\033[K"; 314 331 // Indicate a command prompt 315 std::cout<< this->promptString_;332 this->cout_ << this->promptString_; 316 333 // Save cursor position 317 std::cout<< "\033[s";334 this->cout_ << "\033[s"; 318 335 // Print command line buffer 319 std::cout<< this->shell_->getInput();336 this->cout_ << this->shell_->getInput(); 320 337 // Restore cursor position and move it to the right 321 std::cout<< "\033[u";338 this->cout_ << "\033[u"; 322 339 if (this->buffer_->getCursorPosition() > 0) 323 std::cout<< "\033[" << this->buffer_->getCursorPosition() << "C";340 this->cout_ << "\033[" << this->buffer_->getCursorPosition() << "C"; 324 341 } 325 342 … … 329 346 { 330 347 // Save cursor position 331 std::cout<< "\033[s";348 this->cout_ << "\033[s"; 332 349 // Move cursor down (don't create a new line here because the buffer might flush then!) 333 std::cout << "\033[1E"; 334 std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, "; 335 std::cout << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms tick time"; 350 this->cout_ << "\033[1E"; 351 //this->cout_ << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, "; 352 //this->cout_ << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms tick time"; 353 this->cout_ << "Terminal width: " << this->terminalWidth_ << ", height: " << this->terminalHeight_; 336 354 // Restore cursor position 337 std::cout<< "\033[u";355 this->cout_ << "\033[u"; 338 356 this->bStatusPrinted_ = true; 339 357 } … … 397 415 { 398 416 // Save cursor position and move it to the beginning of the first output line 399 std::cout<< "\033[s\033[1F";417 this->cout_ << "\033[s\033[1F"; 400 418 // Erase the line 401 std::cout<< "\033[K";419 this->cout_ << "\033[K"; 402 420 // Reprint the last output line 403 421 this->printLogText(*(this->shell_->getNewestLineIterator())); 404 422 // Restore cursor 405 std::cout<< "\033[u";406 std::cout.flush();423 this->cout_ << "\033[u"; 424 this->cout_.flush(); 407 425 } 408 426 … … 412 430 // Move cursor to the bottom line 413 431 if (this->bStatusPrinted_) 414 std::cout<< "\033[" << this->statusLineWidths_.size() << 'E';432 this->cout_ << "\033[" << this->statusLineWidths_.size() << 'E'; 415 433 // Create new lines on the screen 416 434 int newLines = this->shell_->getNewestLineIterator()->size() / this->terminalWidth_ + 1; 417 std::cout<< std::string(newLines, '\n');435 this->cout_ << std::string(newLines, '\n'); 418 436 // Move cursor to the beginning of the new (last) output line 419 std::cout<< "\033[" << (newLines + this->statusLineWidths_.size()) << 'F';437 this->cout_ << "\033[" << (newLines + this->statusLineWidths_.size()) << 'F'; 420 438 // Erase screen from here 421 std::cout<< "\033[J";439 this->cout_ << "\033[J"; 422 440 // Print the new output line 423 441 for (int i = 0; i < newLines; ++i) 424 442 this->printLogText(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_)); 425 443 // Move cursor down 426 std::cout<< "\033[1E";444 this->cout_ << "\033[1E"; 427 445 // Print status and input lines 428 446 this->printInputLine(); 429 447 this->printStatusLines(); 430 std::cout.flush();448 this->cout_.flush(); 431 449 } 432 450 } … … 457 475 this->lastTerminalHeight_ = this->terminalHeight_; 458 476 459 // Disable standard std::coutlogging477 // Disable standard this->cout_ logging 460 478 OutputHandler::getInstance().disableCout(); 461 479 */ … … 468 486 this->shell_->destroy(); 469 487 470 // Enable standard std::coutlogging again488 // Enable standard this->cout_ logging again 471 489 OutputHandler::getInstance().enableCout(); 472 490 */ -
code/branches/console/src/libraries/core/IOConsole.h
r6015 r6037 33 33 #include "CorePrereqs.h" 34 34 35 #include <sstream> 35 36 #include <string> 36 37 #include <vector> … … 75 76 Shell* shell_; 76 77 InputBuffer* buffer_; 78 std::ostream cout_; 79 std::ostringstream origCout_; 77 80 unsigned int terminalWidth_; 78 81 unsigned int terminalHeight_;
Note: See TracChangeset
for help on using the changeset viewer.