Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6103


Ignore:
Timestamp:
Nov 20, 2009, 4:05:32 PM (14 years ago)
Author:
rgrieder
Message:

Cleanup in IOConsole

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/libraries/core/IOConsole.cc

    r6089 r6103  
    158158        // Empty all buffers
    159159        this->update(Game::getInstance().getGameClock());
    160         // Goto last line and create a new one
    161         if (this->bStatusPrinted_)
    162             this->cout_ << "\033[" << this->statusLineWidths_.size() << 'E';
    163         this->cout_ << std::endl;
     160        // Erase input and status lines
     161        this->cout_ << "\033[1G\033[J";
    164162
    165163        resetTerminalMode();
     
    175173    void IOConsole::update(const Clock& time)
    176174    {
    177         unsigned char c = 0;
     175        unsigned char c;
    178176        std::string escapeSequence;
    179177        EscapeMode::Value escapeMode = EscapeMode::None;
     
    260258            this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0));
    261259
    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 
    269260        // Determine terminal width and height
    270261        this->lastTerminalWidth_ = this->terminalWidth_;
     
    279270            int newLines = std::min((int)this->statusLineWidths_.size(), -heightDiff);
    280271            // Scroll terminal to create new lines
    281             this->cout_ << "\033[" << newLines << "S";
     272            this->cout_ << "\033[" << newLines << 'S';
    282273        }
    283274
     
    285276        {
    286277            // Scroll console to make way for status lines
    287             this->cout_ << "\033[" << this->statusLineWidths_.size() << "S";
     278            this->cout_ << "\033[" << this->statusLineWidths_.size() << 'S';
    288279            this->bStatusPrinted_ = true;
    289280        }
     281
     282        // We always assume that the cursor is on the inputline.
     283        // But we cannot always be sure about that, esp. if we scroll the console
     284        this->cout_ << "\033[" << this->statusLineWidths_.size() << 'B';
     285        this->cout_ << "\033[" << this->statusLineWidths_.size() << 'A';
     286
    290287        // Erase status and input lines
    291288        this->cout_ << "\033[1G\033[J";
     
    293290        this->printStatusLines();
    294291        this->cout_.flush();
     292
     293        // Process output written to std::cout
     294        if (!this->origCout_.str().empty())
     295        {
     296            this->shell_->addOutputLine(this->origCout_.str());
     297            this->origCout_.str("");
     298        }
    295299    }
    296300
     
    298302    {
    299303        std::string output = text;
    300         int level = this->extractLogLevel(&output);
     304        /*int level =*/ this->extractLogLevel(&output);
    301305
    302306/*
     
    348352            this->cout_ << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, ";
    349353            this->cout_ <<               std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms tick time";
    350 //            this->cout_ << "Terminal width: " << this->terminalWidth_ << ", height: " << this->terminalHeight_;
    351354            // Restore cursor position
    352355            this->cout_ << "\033[u";
     
    425428    void IOConsole::lineAdded()
    426429    {
    427         // Move cursor to the bottom line
    428         if (this->bStatusPrinted_)
    429             this->cout_ << "\033[" << this->statusLineWidths_.size() << "B\033[1G";
    430         // Create new lines on the screen
    431430        int newLines = this->shell_->getNewestLineIterator()->size() / this->terminalWidth_ + 1;
    432         this->cout_ << std::string(newLines, '\n');
     431        // Create new lines by scrolling the screen
     432        this->cout_ << "\033[" << newLines << 'S';
    433433        // Move cursor to the beginning of the new (last) output line
    434         this->cout_ << "\033[" << (newLines + this->statusLineWidths_.size()) << "A\033[1G";
     434        this->cout_ << "\033[" << newLines << "A\033[1G";
    435435        // Erase screen from here
    436436        this->cout_ << "\033[J";
    437         // Print the new output line
     437        // Print the new output lines
    438438        for (int i = 0; i < newLines; ++i)
    439439            this->printLogText(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_));
Note: See TracChangeset for help on using the changeset viewer.