Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 23, 2011, 12:45:53 AM (13 years ago)
Author:
landauf
Message:

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/command/IOConsoleWindows.cc

    r8729 r8858  
    3434#include "util/Clock.h"
    3535#include "util/Math.h"
     36#include "util/output/ConsoleWriter.h"
    3637#include "core/Game.h"
    3738#include "core/input/InputBuffer.h"
     
    4344    //! Redirects std::cout, creates the corresponding Shell and changes the terminal mode
    4445    IOConsole::IOConsole()
    45         : shell_(new Shell("IOConsole", false))
     46        : shell_(new Shell("Console", false))
    4647        , buffer_(shell_->getInputBuffer())
    4748        , cout_(std::cout.rdbuf())
     
    5253    {
    5354        // Disable standard this->cout_ logging
    54         OutputHandler::getInstance().disableCout();
     55        ConsoleWriter::getInstance().disable();
    5556        // Redirect std::cout to an ostringstream
    5657        // (Other part is in the initialiser list)
     
    9596        std::cout.flush();
    9697        if (!this->origCout_.str().empty())
    97             this->shell_->addOutput(this->origCout_.str(), Shell::None);
     98            this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
    9899
    99100        this->shell_->unregisterListener(this);
     
    108109        std::cout.rdbuf(this->cout_.rdbuf());
    109110        // Enable standard this->cout_ logging again
    110         OutputHandler::getInstance().enableCout();
     111        ConsoleWriter::getInstance().enable();
    111112
    112113        resetTerminalMode();
     
    188189        if (!this->origCout_.str().empty())
    189190        {
    190             this->shell_->addOutput(this->origCout_.str(), Shell::None);
     191            this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
    191192            this->origCout_.str("");
    192193        }
     
    200201        switch (type)
    201202        {
    202         case Shell::Error:   colour = FOREGROUND_INTENSITY                    | FOREGROUND_RED; break;
    203         case Shell::Warning: colour = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED; break;
    204         case Shell::Info:
    205         case Shell::Debug:
    206         case Shell::Verbose:
    207         case Shell::Ultra:   colour = FOREGROUND_INTENSITY                                     ; break;
    208         case Shell::Command: colour =                        FOREGROUND_GREEN                  | FOREGROUND_BLUE; break;
    209         case Shell::Hint:    colour =                        FOREGROUND_GREEN | FOREGROUND_RED                  ; break;
    210         case Shell::TDebug:  colour = FOREGROUND_INTENSITY                    | FOREGROUND_RED | FOREGROUND_BLUE; break;
    211         default:             colour =                        FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; break;
     203            case Shell::Message:
     204            case Shell::DebugOutput:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     205
     206            case Shell::UserError:       colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | 0              ; break;
     207            case Shell::UserWarning:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
     208            case Shell::UserStatus:      colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | 0              ; break;
     209            case Shell::UserInfo:        colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     210
     211            case Shell::InternalError:   colour = 0                    | FOREGROUND_RED | 0                | 0              ; break;
     212            case Shell::InternalWarning: colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
     213            case Shell::InternalStatus:  colour = 0                    | 0              | FOREGROUND_GREEN | 0              ; break;
     214            case Shell::InternalInfo:    colour = 0                    | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     215
     216            case Shell::Verbose:         colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     217            case Shell::VerboseMore:     colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     218            case Shell::VerboseUltra:    colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     219
     220            case Shell::Command:         colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
     221            case Shell::Hint:            colour = 0                    | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
     222
     223            default:                     colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
    212224        }
    213225
     
    238250            || !SetConsoleMode(this->stdInHandle_, 0))
    239251        {
    240             COUT(1) << "Error: Could not set Windows console settings" << std::endl;
     252            orxout(user_error) << "Could not set Windows console settings" << endl;
    241253            return;
    242254        }
     
    318330    void IOConsole::executed()
    319331    {
    320         this->shell_->addOutput(this->promptString_ + this->shell_->getInput() + '\n', Shell::Command);
     332        this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::Command);
    321333    }
    322334
     
    377389    }
    378390
    379     //! Called if only the last output-line has changed
    380     void IOConsole::onlyLastLineChanged()
    381     {
    382         int newLineHeight = 1 + this->shell_->getNewestLineIterator()->first.size() / this->terminalWidth_;
    383         // Compute the number of new lines needed
    384         int newLines = newLineHeight - this->lastOutputLineHeight_;
    385         this->lastOutputLineHeight_ = newLineHeight;
    386         // Scroll console if necessary
    387         if (newLines > 0) // newLines < 0 is assumed impossible
    388             this->createNewOutputLines(newLines);
    389         Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
    390         this->printOutputLine(it->first, it->second, makeCOORD(0, this->inputLineRow_ - newLineHeight));
    391     }
    392 
    393391    //! Called if a new output line was added
    394392    void IOConsole::lineAdded()
Note: See TracChangeset for help on using the changeset viewer.