[Orxonox-commit 1462] r6180 - in code/branches/presentation2/src: libraries/core orxonox/overlays
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Nov 29 22:43:44 CET 2009
Author: rgrieder
Date: 2009-11-29 22:43:43 +0100 (Sun, 29 Nov 2009)
New Revision: 6180
Modified:
code/branches/presentation2/src/libraries/core/IOConsole.cc
code/branches/presentation2/src/libraries/core/IOConsole.h
code/branches/presentation2/src/libraries/core/Shell.cc
code/branches/presentation2/src/libraries/core/Shell.h
code/branches/presentation2/src/orxonox/overlays/InGameConsole.cc
code/branches/presentation2/src/orxonox/overlays/InGameConsole.h
Log:
Extended Shell line colouring in order to distinguish output from COUT, entered commands and hints.
Modified: code/branches/presentation2/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/IOConsole.cc 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/libraries/core/IOConsole.cc 2009-11-29 21:43:43 UTC (rev 6180)
@@ -44,24 +44,6 @@
{
IOConsole* IOConsole::singletonPtr_s = NULL;
- //! Extracts the log level associated to a string (first character)
- int IOConsole::extractLogLevel(std::string* text)
- {
- // Handle line colouring by inspecting the first letter
- char level = 0;
- if (!text->empty())
- {
- level = (*text)[0];
- if (level == -1 || (level >= 1 && level <= 6))
- {
- *text = text->substr(1);
- if (level != -1)
- return level;
- }
- }
- return 0;
- }
-
// ###############################
// ### ShellListener methods ###
// ###############################
@@ -77,7 +59,7 @@
//! Called if a command is about to be executed
void IOConsole::executed()
{
- this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());
+ this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput(), Shell::Command);
}
//! Called if the console gets closed
@@ -108,7 +90,7 @@
}
IOConsole::IOConsole()
- : shell_(new Shell("IOConsole", false, true))
+ : shell_(new Shell("IOConsole", false))
, buffer_(shell_->getInputBuffer())
, cout_(std::cout.rdbuf())
, promptString_("orxonox # ")
@@ -279,33 +261,30 @@
// Process output written to std::cout
if (!this->origCout_.str().empty())
{
- this->shell_->addOutputLine(this->origCout_.str());
+ this->shell_->addOutputLine(this->origCout_.str(), Shell::None);
this->origCout_.str("");
}
}
- void IOConsole::printOutputLine(const std::string& text)
+ void IOConsole::printOutputLine(const std::string& text, Shell::LineType type)
{
- std::string output = text;
- /*int level =*/ this->extractLogLevel(&output);
-
/*
// Colour line
- switch (level)
+ switch (type)
{
- case -1: this->cout_ << "\033[37m"; break;
- case 1: this->cout_ << "\033[91m"; break;
- case 2: this->cout_ << "\033[31m"; break;
- case 3: this->cout_ << "\033[34m"; break;
- case 4: this->cout_ << "\033[36m"; break;
- case 5: this->cout_ << "\033[35m"; break;
- case 6: this->cout_ << "\033[37m"; break;
+ case Shell::None: this->cout_ << "\033[37m"; break;
+ case Shell::Error: this->cout_ << "\033[91m"; break;
+ case Shell::Warning: this->cout_ << "\033[31m"; break;
+ case Shell::Info: this->cout_ << "\033[34m"; break;
+ case Shell::Debug: this->cout_ << "\033[36m"; break;
+ case Shell::Verbose: this->cout_ << "\033[35m"; break;
+ case Shell::Ultra: this->cout_ << "\033[37m"; break;
default: break;
}
*/
// Print output line
- this->cout_ << output;
+ this->cout_ << text;
// Reset colour to white
// this->cout_ << "\033[37m";
@@ -418,7 +397,7 @@
// Erase the line
this->cout_ << "\033[K";
// Reprint the last output line
- this->printOutputLine(*(this->shell_->getNewestLineIterator()));
+ this->printOutputLine(this->shell_->getNewestLineIterator()->first);
// Restore cursor
this->cout_ << "\033[u";
this->cout_.flush();
@@ -427,7 +406,7 @@
//! Called if a new output-line was added
void IOConsole::lineAdded()
{
- int newLines = this->shell_->getNewestLineIterator()->size() / this->terminalWidth_ + 1;
+ int newLines = this->shell_->getNewestLineIterator()->first.size() / this->terminalWidth_ + 1;
// Create new lines by scrolling the screen
this->cout_ << "\033[" << newLines << 'S';
// Move cursor to the beginning of the new (last) output line
@@ -436,7 +415,7 @@
this->cout_ << "\033[J";
// Print the new output lines
for (int i = 0; i < newLines; ++i)
- this->printOutputLine(this->shell_->getNewestLineIterator()->substr(i*this->terminalWidth_, this->terminalWidth_));
+ this->printOutputLine(this->shell_->getNewestLineIterator()->first.substr(i*this->terminalWidth_, this->terminalWidth_));
// Move cursor down
this->cout_ << "\033[1B\033[1G";
// Print status and input lines
@@ -471,7 +450,7 @@
{
//! Redirects std::cout, creates the corresponding Shell and changes the terminal mode
IOConsole::IOConsole()
- : shell_(new Shell("IOConsole", false, true))
+ : shell_(new Shell("IOConsole", false))
, buffer_(shell_->getInputBuffer())
, cout_(std::cout.rdbuf())
, promptString_("orxonox # ")
@@ -612,30 +591,31 @@
// Process output written to std::cout
if (!this->origCout_.str().empty())
{
- this->shell_->addOutputLine(this->origCout_.str());
+ this->shell_->addOutputLine(this->origCout_.str(), Shell::None);
this->origCout_.str("");
}
}
//! Prints output text. Similar to writeText, but sets the colour according to the output level
- void IOConsole::printOutputLine(const std::string& text, const COORD& pos)
+ void IOConsole::printOutputLine(const std::string& text, Shell::LineType type, const COORD& pos)
{
- std::string output = text;
- int level = this->extractLogLevel(&output);
-
// Colour line
WORD colour = 0;
- switch (level)
+ switch (type)
{
- case 1: colour = FOREGROUND_INTENSITY | FOREGROUND_RED ; break;
- case 2: colour = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED ; break;
- case 3: colour = FOREGROUND_INTENSITY ; break;
- case 4: colour = FOREGROUND_INTENSITY ; break;
- default: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ; break;
+ case Shell::Error: colour = FOREGROUND_INTENSITY | FOREGROUND_RED; break;
+ case Shell::Warning: colour = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED; break;
+ case Shell::Info:
+ case Shell::Debug:
+ case Shell::Verbose:
+ case Shell::Ultra: colour = FOREGROUND_INTENSITY ; break;
+ case Shell::Command: colour = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
+ case Shell::Hint: colour = FOREGROUND_GREEN | FOREGROUND_RED ; break;
+ default: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; break;
}
// Print output line
- this->writeText(output, pos, colour);
+ this->writeText(text, pos, colour);
}
//! Prints all status lines with current content
@@ -782,25 +762,27 @@
//! Called if only the last output-line has changed
void IOConsole::onlyLastLineChanged()
{
- int newLineHeight = 1 + this->shell_->getNewestLineIterator()->size() / this->terminalWidth_;
+ int newLineHeight = 1 + this->shell_->getNewestLineIterator()->first.size() / this->terminalWidth_;
// Compute the number of new lines needed
int newLines = newLineHeight - this->lastOutputLineHeight_;
this->lastOutputLineHeight_ = newLineHeight;
// Scroll console if necessary
if (newLines > 0) // newLines < 0 is assumed impossible
this->createNewOutputLines(newLines);
- this->printOutputLine(*(this->shell_->getNewestLineIterator()), makeCOORD(0, this->inputLineRow_ - newLineHeight));
+ Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
+ this->printOutputLine(it->first, it->second, makeCOORD(0, this->inputLineRow_ - newLineHeight));
}
//! Called if a new output line was added
void IOConsole::lineAdded()
{
+ Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
// Scroll console
- this->lastOutputLineHeight_ = 1 + this->shell_->getNewestLineIterator()->size() / this->terminalWidth_;
+ this->lastOutputLineHeight_ = 1 + it->first.size() / this->terminalWidth_;
this->createNewOutputLines(this->lastOutputLineHeight_);
// Write the text
COORD pos = {0, this->inputLineRow_ - this->lastOutputLineHeight_};
- this->printOutputLine(*(this->shell_->getNewestLineIterator()), pos);
+ this->printOutputLine(it->first, it->second, pos);
}
}
Modified: code/branches/presentation2/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/presentation2/src/libraries/core/IOConsole.h 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/libraries/core/IOConsole.h 2009-11-29 21:43:43 UTC (rev 6180)
@@ -86,7 +86,7 @@
#ifdef ORXONOX_PLATFORM_UNIX
bool willPrintStatusLines();
void printInputLine();
- void printOutputLine(const std::string& line);
+ void printOutputLine(const std::string& line, Shell::LineType type);
static void resetTerminalMode();
bool bPrintStatusLine_;
@@ -101,7 +101,7 @@
void moveCursor(int dx, int dy);
void writeText(const std::string& text, const COORD& pos, WORD attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
void createNewOutputLines(int lines);
- void printOutputLine(const std::string& line, const COORD& pos);
+ void printOutputLine(const std::string& line, Shell::LineType type, const COORD& pos);
static inline COORD makeCOORD(int x, int y)
{
Modified: code/branches/presentation2/src/libraries/core/Shell.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Shell.cc 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/libraries/core/Shell.cc 2009-11-29 21:43:43 UTC (rev 6180)
@@ -44,11 +44,10 @@
SetConsoleCommandShortcut(OutputHandler, info);
SetConsoleCommandShortcut(OutputHandler, debug);
- Shell::Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel)
+ Shell::Shell(const std::string& consoleName, bool bScrollable)
: OutputListener(consoleName)
, inputBuffer_(new InputBuffer())
, consoleName_(consoleName)
- , bPrependOutputLevel_(bPrependOutputLevel)
, bScrollable_(bScrollable)
{
RegisterRootObject(Shell);
@@ -190,14 +189,13 @@
this->updateListeners<&ShellListener::cursorChanged>();
}
- void Shell::addOutputLine(const std::string& line, int level)
+ void Shell::addOutputLine(const std::string& line, LineType type)
{
// Make sure we really only have one line per line (no new lines!)
SubString lines(line, '\n');
for (unsigned i = 0; i < lines.size(); ++i)
{
- if (level <= this->softDebugLevel_)
- this->outputLines_.push_front(lines[i]);
+ this->outputLines_.push_front(std::make_pair(lines[i], type));
this->updateListeners<&ShellListener::lineAdded>();
}
}
@@ -213,7 +211,7 @@
this->updateListeners<&ShellListener::linesChanged>();
}
- std::list<std::string>::const_iterator Shell::getNewestLineIterator() const
+ Shell::LineList::const_iterator Shell::getNewestLineIterator() const
{
if (this->scrollPosition_)
return this->scrollIterator_;
@@ -221,7 +219,7 @@
return this->outputLines_.begin();
}
- std::list<std::string>::const_iterator Shell::getEndIterator() const
+ Shell::LineList::const_iterator Shell::getEndIterator() const
{
return this->outputLines_.end();
}
@@ -263,16 +261,8 @@
if (this->bFinishedLastLine_)
{
- if (this->bPrependOutputLevel_)
- {
- if (level == 0)
- output.insert(0, 1, static_cast<char>(-1));
- else
- output.insert(0, 1, static_cast<char>(level));
- }
+ this->outputLines_.push_front(std::make_pair(output, static_cast<LineType>(level)));
- this->outputLines_.push_front(output);
-
if (this->scrollPosition_)
this->scrollPosition_++;
else
@@ -287,7 +277,7 @@
}
else
{
- (*this->outputLines_.begin()) += output;
+ this->outputLines_.front().first += output;
this->bFinishedLastLine_ = newline;
this->updateListeners<&ShellListener::onlyLastLineChanged>();
}
@@ -324,7 +314,7 @@
this->updateListeners<&ShellListener::executed>();
if (!CommandExecutor::execute(this->inputBuffer_->get()))
- this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
+ this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", Error);
this->clearInput();
}
@@ -332,7 +322,7 @@
void Shell::hintAndComplete()
{
this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get()));
- this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
+ this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), Hint);
this->inputChanged();
}
Modified: code/branches/presentation2/src/libraries/core/Shell.h
===================================================================
--- code/branches/presentation2/src/libraries/core/Shell.h 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/libraries/core/Shell.h 2009-11-29 21:43:43 UTC (rev 6180)
@@ -64,7 +64,21 @@
class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
{
public:
- Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false);
+ enum LineType
+ {
+ None = OutputLevel::None,
+ Warning = OutputLevel::Warning,
+ Error = OutputLevel::Error,
+ Info = OutputLevel::Info,
+ Debug = OutputLevel::Debug,
+ Verbose = OutputLevel::Verbose,
+ Ultra = OutputLevel::Ultra,
+ Input,
+ Command,
+ Hint
+ };
+
+ Shell(const std::string& consoleName, bool bScrollable);
~Shell();
void setConfigValues();
@@ -84,10 +98,11 @@
inline std::string getInput() const
{ return this->inputBuffer_->get(); }
- std::list<std::string>::const_iterator getNewestLineIterator() const;
- std::list<std::string>::const_iterator getEndIterator() const;
+ typedef std::list<std::pair<std::string, LineType> > LineList;
+ LineList::const_iterator getNewestLineIterator() const;
+ LineList::const_iterator getEndIterator() const;
- void addOutputLine(const std::string& line, int level = 0);
+ void addOutputLine(const std::string& line, LineType type = None);
void clearOutput();
inline unsigned int getNumLines() const
@@ -138,15 +153,14 @@
InputBuffer* inputBuffer_;
std::stringstream outputBuffer_;
bool bFinishedLastLine_;
- std::list<std::string> outputLines_;
- std::list<std::string>::const_iterator scrollIterator_;
+ LineList outputLines_;
+ LineList::const_iterator scrollIterator_;
unsigned int scrollPosition_;
unsigned int historyPosition_;
ConfigFileType commandHistoryConfigFileType_;
std::string promptPrefix_;
const std::string consoleName_;
- const bool bPrependOutputLevel_;
const bool bScrollable_;
// Config values
Modified: code/branches/presentation2/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/presentation2/src/orxonox/overlays/InGameConsole.cc 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/orxonox/overlays/InGameConsole.cc 2009-11-29 21:43:43 UTC (rev 6180)
@@ -67,7 +67,7 @@
@brief Constructor: Creates and initializes the InGameConsole.
*/
InGameConsole::InGameConsole()
- : shell_(new Shell("InGameConsole", true, true))
+ : shell_(new Shell("InGameConsole", true))
, consoleOverlay_(0)
, consoleOverlayContainer_(0)
, consoleOverlayNoise_(0)
@@ -267,7 +267,7 @@
*/
void InGameConsole::linesChanged()
{
- std::list<std::string>::const_iterator it = this->shell_->getNewestLineIterator();
+ Shell::LineList::const_iterator it = this->shell_->getNewestLineIterator();
int max = 0;
for (int i = 1; i < LINES; ++i)
{
@@ -281,12 +281,12 @@
}
for (int i = LINES - 1; i > max; --i)
- this->print("", i, true);
+ this->print("", Shell::None, i, true);
for (int i = max; i >= 1; --i)
{
--it;
- this->print(*it, i, true);
+ this->print(it->first, it->second, i, true);
}
}
@@ -296,7 +296,7 @@
void InGameConsole::onlyLastLineChanged()
{
if (LINES > 1)
- this->print(*this->shell_->getNewestLineIterator(), 1);
+ this->print(this->shell_->getNewestLineIterator()->first, this->shell_->getNewestLineIterator()->second, 1);
}
/**
@@ -315,7 +315,7 @@
void InGameConsole::inputChanged()
{
if (LINES > 0)
- this->print(this->shell_->getInput(), 0);
+ this->print(this->shell_->getInput(), Shell::Input, 0);
if (this->shell_->getInput() == "" || this->shell_->getInput().size() == 0)
this->inputWindowStart_ = 0;
@@ -339,7 +339,7 @@
*/
void InGameConsole::executed()
{
- this->shell_->addOutputLine(this->shell_->getInput());
+ this->shell_->addOutputLine(this->shell_->getInput(), Shell::Command);
}
/**
@@ -455,20 +455,12 @@
@brief Prints string to bottom line.
@param s String to be printed
*/
- void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
+ void InGameConsole::print(const std::string& text, Shell::LineType type, int index, bool alwaysShift)
{
- char level = 0;
- if (text.size() > 0)
- level = text[0];
-
std::string output = text;
-
- if (level >= -1 && level <= 5)
- output.erase(0, 1);
-
if (LINES > index)
{
- this->colourLine(level, index);
+ this->colourLine(type, index);
if (index > 0)
{
@@ -481,7 +473,7 @@
output.insert(0, 1, ' ');
if (linesUsed > numLinesShifted_ || alwaysShift)
this->shiftLines();
- this->colourLine(level, index);
+ this->colourLine(type, index);
}
this->consoleOverlayTextAreas_[index]->setCaption(multi_cast<Ogre::DisplayString>(output));
this->displayedText_ = output;
@@ -558,43 +550,41 @@
}
}
- void InGameConsole::colourLine(int colourcode, int index)
+ void InGameConsole::colourLine(Shell::LineType type, int index)
{
- if (colourcode == -1)
+ ColourValue colourTop, colourBottom;
+ switch (type)
{
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
+ case Shell::Error: colourTop = ColourValue(0.95, 0.25, 0.25, 1.00);
+ colourBottom = ColourValue(1.00, 0.50, 0.50, 1.00); break;
+
+ case Shell::Warning: colourTop = ColourValue(0.95, 0.50, 0.20, 1.00);
+ colourBottom = ColourValue(1.00, 0.70, 0.50, 1.00); break;
+
+ case Shell::Info: colourTop = ColourValue(0.50, 0.50, 0.95, 1.00);
+ colourBottom = ColourValue(0.80, 0.80, 1.00, 1.00); break;
+
+ case Shell::Debug: colourTop = ColourValue(0.65, 0.48, 0.44, 1.00);
+ colourBottom = ColourValue(1.00, 0.90, 0.90, 1.00); break;
+
+ case Shell::Verbose: colourTop = ColourValue(0.40, 0.20, 0.40, 1.00);
+ colourBottom = ColourValue(0.80, 0.60, 0.80, 1.00); break;
+
+ case Shell::Ultra: colourTop = ColourValue(0.21, 0.69, 0.21, 1.00);
+ colourBottom = ColourValue(0.80, 1.00, 0.80, 1.00); break;
+
+ case Shell::Command: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00);
+ colourBottom = ColourValue(0.90, 0.90, 0.90, 0.90); break;
+
+ case Shell::Hint: colourTop = ColourValue(0.80, 0.80, 0.80, 1.00);
+ colourBottom = ColourValue(0.90, 0.90, 0.90, 1.00); break;
+
+ default: colourTop = ColourValue(0.90, 0.90, 0.90, 1.00);
+ colourBottom = ColourValue(1.00, 1.00, 1.00, 1.00); break;
}
- else if (colourcode == 1)
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
- }
- else if (colourcode == 2)
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
- }
- else if (colourcode == 3)
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
- }
- else if (colourcode == 4)
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
- }
- else if (colourcode == 5)
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
- }
- else
- {
- this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00));
- this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
- }
+
+ this->consoleOverlayTextAreas_[index]->setColourTop (colourTop);
+ this->consoleOverlayTextAreas_[index]->setColourBottom(colourBottom);
}
// ################################
Modified: code/branches/presentation2/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/branches/presentation2/src/orxonox/overlays/InGameConsole.h 2009-11-29 20:27:22 UTC (rev 6179)
+++ code/branches/presentation2/src/orxonox/overlays/InGameConsole.h 2009-11-29 21:43:43 UTC (rev 6180)
@@ -71,9 +71,9 @@
void exit();
void shiftLines();
- void colourLine(int colourcode, int index);
+ void colourLine(Shell::LineType type, int index);
void setCursorPosition(unsigned int pos);
- void print(const std::string& text, int index, bool alwaysShift = false);
+ void print(const std::string& text, Shell::LineType type, int index, bool alwaysShift = false);
void windowResized(unsigned int newWidth, unsigned int newHeight);
More information about the Orxonox-commit
mailing list