[Orxonox-commit 1296] r6014 - code/branches/console/src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Nov 2 13:57:19 CET 2009
Author: rgrieder
Date: 2009-11-02 13:57:19 +0100 (Mon, 02 Nov 2009)
New Revision: 6014
Modified:
code/branches/console/src/libraries/core/IOConsole.cc
code/branches/console/src/libraries/core/IOConsole.h
Log:
IOConsole: More line wrapping fixes
Modified: code/branches/console/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.cc 2009-11-01 14:57:56 UTC (rev 6013)
+++ code/branches/console/src/libraries/core/IOConsole.cc 2009-11-02 12:57:19 UTC (rev 6014)
@@ -44,6 +44,8 @@
#ifdef ORXONOX_PLATFORM_UNIX
#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
#endif
namespace orxonox
@@ -73,8 +75,12 @@
this->shell_->registerListener(this);
// Manually set the widths of the individual status lines
- this->statusLineWidths_.push_back(20);
- this->statusLineMaxWidth_ = 20;
+ this->statusLineWidths_.push_back(29);
+ this->statusLineMaxWidth_ = 29;
+
+ this->getTerminalSize();
+ this->lastTerminalWidth_ = this->terminalWidth_;
+ this->lastTerminalHeight_ = this->terminalHeight_;
}
IOConsole::~IOConsole()
@@ -191,17 +197,30 @@
this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0));
// Determine terminal width and height
+ this->lastTerminalWidth_ = this->terminalWidth_;
+ this->lastTerminalHeight_ = this->terminalHeight_;
this->getTerminalSize();
+ int heightDiff = this->terminalHeight_ - this->lastTerminalHeight_;
+ if (this->bStatusPrinted_ && heightDiff < 0)
+ {
+ // Terminal width has shrinked. The cursor will still be on the input line,
+ // but that line might very well be the last
+ int newLines = std::min((int)this->statusLineWidths_.size(), -heightDiff);
+ std::cout << std::string(newLines, '\n');
+ // Move cursor up again
+ std::cout << "\033[" << newLines << 'F';
+ }
+
if (!this->bStatusPrinted_ && this->willPrintStatusLines())
{
// Print new lines to make way for status lines
std::cout << std::string(this->statusLineWidths_.size(), '\n');
// Move cursor up again
- std::cout << "\033[" << this->statusLineWidths_.size() << 'A';
+ std::cout << "\033[" << this->statusLineWidths_.size() << 'F';
this->bStatusPrinted_ = true;
}
- // Move cursor horizontally and erase status and input lines
+ // Erase status and input lines
std::cout << "\033[1G\033[J";
this->printInputLine();
this->printStatusLines();
@@ -392,14 +411,16 @@
// Move cursor to the bottom line
if (this->bStatusPrinted_)
std::cout << "\033[" << this->statusLineWidths_.size() << 'E';
- // Create the new line on the screen
- std::cout << '\n';
+ // Create new lines on the screen
+ int newLines = this->shell_->getNewestLineIterator()->size() / this->terminalWidth_ + 1;
+ std::cout << std::string(newLines, '\n');
// Move cursor to the beginning of the new (last) output line
- std::cout << "\033[" << (1 + this->statusLineWidths_.size()) << 'F';
+ std::cout << "\033[" << (newLines + this->statusLineWidths_.size()) << 'F';
// Erase screen from here
std::cout << "\033[J";
// Print the new output line
- this->printLogText(*(this->shell_->getNewestLineIterator()));
+ for (int i = 0; i < newLines; ++i)
+ this->printLogText(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_));
// Move cursor down
std::cout << "\033[1E";
// Print status and input lines
Modified: code/branches/console/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.h 2009-11-01 14:57:56 UTC (rev 6013)
+++ code/branches/console/src/libraries/core/IOConsole.h 2009-11-02 12:57:19 UTC (rev 6014)
@@ -76,6 +76,8 @@
termios* originalTerminalSettings_;
unsigned int terminalWidth_;
unsigned int terminalHeight_;
+ unsigned int lastTerminalWidth_;
+ unsigned int lastTerminalHeight_;
bool bPrintStatusLine_;
bool bStatusPrinted_;
std::vector<unsigned> statusLineWidths_;
More information about the Orxonox-commit
mailing list