Changeset 6004 for code/branches/console/src/libraries/core/IOConsole.cc
- Timestamp:
- Oct 30, 2009, 12:39:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/IOConsole.cc
r5998 r6004 52 52 const std::string promptString_g = "orxonox>"; 53 53 54 #if 1//def ORXONOX_PLATFORM_UNIX54 #ifdef ORXONOX_PLATFORM_UNIX 55 55 56 56 termios* IOConsole::originalTerminalSettings_; … … 67 67 68 68 IOConsole::IOConsole() 69 : shell_(Shell::getInstance()) 70 , buffer_(Shell::getInstance().getInputBuffer()) 69 : shell_(new Shell("IOConsole", false)) 70 , buffer_(shell_->getInputBuffer()) 71 , originalTerminalSettings_(new termios()) 71 72 , bStatusPrinted_(false) 72 73 { 73 this->originalTerminalSettings_ = new termios;74 74 this->setTerminalMode(); 75 this->shell_.registerListener(this); 76 75 this->shell_->registerListener(this); 77 76 78 77 // Manually set the widths of the individual status lines 79 this->statusLineWidths_.push_back(20); 78 this->statusLineWidths_.push_back(6); 79 this->statusLineMaxWidth_ = 6; 80 80 } 81 81 … … 86 86 resetTerminalMode(); 87 87 delete this->originalTerminalSettings_; 88 this->shell_->destroy(); 88 89 } 89 90 … … 189 190 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0)); 190 191 191 // Print input line 192 // Clear screen below the last output line by first moving the cursor to the beginning of the first status line 193 std::cout << "\033[" << (this->bStatusPrinted_ ? this->statusLineWidths_.size() : 0) << "F\033[J"; 194 this->printStatusLines(); 192 195 this->printInputLine(); 193 196 } … … 233 236 // Set cursor to the beginning of the line and erase the line 234 237 std::cout << "\033[1G\033[K"; 235 // Print status line236 //std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";237 238 // Indicate a command prompt 238 239 std::cout << promptString_g; … … 240 241 std::cout << "\033[s"; 241 242 // Print command line buffer 242 std::cout << this->shell_ .getInput();243 std::cout << this->shell_->getInput(); 243 244 // Restore cursor position and move it to the right 244 245 std::cout << "\033[u"; … … 252 253 if (!this->statusLineWidths_.empty()) 253 254 { 254 if (this->bStatusPrinted_)255 {256 // Erase the status lines first (completely, including new lines!)257 258 }259 255 // Check terminal size 260 /*261 256 int x, y; 262 if (this->getTerminalSize(&x, &y) && (x < statusTextWidth_g || y < (2 + statusTextHeight_g)))257 if (this->getTerminalSize(&x, &y) && (x < (int)this->statusLineMaxWidth_ || y < (int)(this->minOutputLines_ + this->statusLineWidths_.size()))) 263 258 { 264 259 this->bStatusPrinted_ = false; 265 260 return; 266 261 } 267 */ 262 std::cout << "Status" << std::endl; 263 std::cout.flush(); 264 this->bStatusPrinted_ = true; 268 265 } 269 266 } … … 307 304 308 305 IOConsole::IOConsole() 309 : shell_( Shell::getInstance())310 , buffer_( Shell::getInstance().getInputBuffer())306 : shell_(new Shell("IOConsole", false)) 307 , buffer_(shell_->getInputBuffer()) 311 308 { 312 309 this->setTerminalMode(); … … 329 326 } 330 327 331 void IOConsole::print (const std::string& text)328 void IOConsole::printLogText(const std::string& text) 332 329 { 333 330 } … … 360 357 { 361 358 // Save cursor position and move it to the beginning of the first output line 362 std::cout << "\033[s\033[" << (1 + 0/*statusTextHeight_g*/) << "F";359 std::cout << "\033[s\033[" << (1 + this->statusLineWidths_.size()) << "F"; 363 360 // Erase the line 364 361 std::cout << "\033[K"; 365 362 // Reprint the last output line 366 this->printLogText(*(this->shell_ .getNewestLineIterator()));363 this->printLogText(*(this->shell_->getNewestLineIterator())); 367 364 // Restore cursor 368 365 std::cout << "\033[u"; … … 376 373 void IOConsole::lineAdded() 377 374 { 378 // Save cursor and move it to the beginning of the first status line 379 std::cout << "\033[s\033[" << 0/*statusTextHeight_g*/ << "F"; 380 // Create a new line and move cursor to the beginning of it (one cell up) 381 std::cout << std::endl << "\033[1F"; 375 // Move cursor to the beginning of the first status line and erase screen from there 376 std::cout << "\033[" << this->statusLineWidths_.size() << "F\033[J"; 382 377 // Print the new output line 383 this->printLogText(*(this->shell_ .getNewestLineIterator()));384 // Restore cursor (for horizontal position) and move it down again (just in case the lines were shifted)385 std::cout << "\033[u\033[" << (1 + 0/*statusTextHeight_g*/) << "B";386 std::cout.flush();378 this->printLogText(*(this->shell_->getNewestLineIterator())); 379 std::cout << std::endl; 380 this->printStatusLines(); 381 this->printInputLine(); 387 382 } 388 383 … … 414 409 std::cout << "\033[1G"; 415 410 // Print command so the user knows what he has typed 416 std::cout << promptString_g << this->shell_ .getInput() << std::endl;411 std::cout << promptString_g << this->shell_->getInput() << std::endl; 417 412 this->printInputLine(); 418 413 }
Note: See TracChangeset
for help on using the changeset viewer.