[Orxonox-commit 1297] r6015 - in code/branches/console/src: libraries/core libraries/util orxonox/overlays
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Nov 2 17:54:13 CET 2009
Author: rgrieder
Date: 2009-11-02 17:54:13 +0100 (Mon, 02 Nov 2009)
New Revision: 6015
Modified:
code/branches/console/src/libraries/core/Core.cc
code/branches/console/src/libraries/core/Core.h
code/branches/console/src/libraries/core/IOConsole.cc
code/branches/console/src/libraries/core/IOConsole.h
code/branches/console/src/libraries/util/OutputHandler.cc
code/branches/console/src/libraries/util/OutputHandler.h
code/branches/console/src/orxonox/overlays/InGameConsole.cc
code/branches/console/src/orxonox/overlays/InGameConsole.h
Log:
IOConsole cleanup and added ConsoleWriter to the OutputHandler so that we get std::cout output before the creation of the IOConsole.
Modified: code/branches/console/src/libraries/core/Core.cc
===================================================================
--- code/branches/console/src/libraries/core/Core.cc 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/core/Core.cc 2009-11-02 16:54:13 UTC (rev 6015)
@@ -217,6 +217,9 @@
// Required as well for the config values
this->languageInstance_.reset(new Language());
+ // create persistent io console
+ this->ioConsole_.reset(new IOConsole());
+
// creates the class hierarchy for all classes with factories
Identifier::createClassHierarchy();
@@ -231,9 +234,6 @@
this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));
this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
- // create persistent io console
- this->ioConsole_.reset(new IOConsole());
-
// Create singletons that always exist (in other libraries)
this->rootScope_.reset(new Scope<ScopeID::Root>());
}
Modified: code/branches/console/src/libraries/core/Core.h
===================================================================
--- code/branches/console/src/libraries/core/Core.h 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/core/Core.h 2009-11-02 16:54:13 UTC (rev 6015)
@@ -90,10 +90,10 @@
SimpleScopeGuard consoleCommandDestroyer_;
scoped_ptr<ConfigFileManager> configFileManager_;
scoped_ptr<Language> languageInstance_;
+ scoped_ptr<IOConsole> ioConsole_;
scoped_ptr<CoreConfiguration> configuration_;
scoped_ptr<TclBind> tclBind_;
scoped_ptr<TclThreadManager> tclThreadManager_;
- scoped_ptr<IOConsole> ioConsole_;
// graphical
scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE
scoped_ptr<InputManager> inputManager_; //!< Interface to OIS
Modified: code/branches/console/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.cc 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/core/IOConsole.cc 2009-11-02 16:54:13 UTC (rev 6015)
@@ -29,31 +29,92 @@
#include "IOConsole.h"
-#include <cstring>
#include <iomanip>
#include <iostream>
-
-#include "util/Clock.h"
-#include "util/Debug.h"
-#include "util/Sleep.h"
-#include "core/CommandExecutor.h"
#include "core/Game.h"
-#include "core/GameMode.h"
-#include "core/Shell.h"
#include "core/input/InputBuffer.h"
+// ##########################
+// ### Mutual methods ###
+// ##########################
+namespace orxonox
+{
+ IOConsole* IOConsole::singletonPtr_s = NULL;
+
+ 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;
+ }
+
+ inline bool IOConsole::willPrintStatusLines()
+ {
+ return !this->statusLineWidths_.empty()
+ && this->terminalWidth_ >= this->statusLineMaxWidth_
+ && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size());
+ }
+
+ // ###############################
+ // ### ShellListener methods ###
+ // ###############################
+
+ //! Called if all output-lines have to be reprinted
+ void IOConsole::linesChanged()
+ {
+ // Method only gets called upon start to draw all the lines
+ // or when scrolling. But scrolling is disable and the output
+ // is already in std::cout when we start the IOConsole
+ }
+
+ //! Called if the text in the input-line has changed
+ void IOConsole::inputChanged()
+ {
+ this->printInputLine();
+ std::cout.flush();
+ }
+
+ //! Called if the position of the cursor in the input-line has changed
+ void IOConsole::cursorChanged()
+ {
+ this->printInputLine();
+ std::cout.flush();
+ }
+
+ //! Called if a command is about to be executed
+ void IOConsole::executed()
+ {
+ this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());
+ }
+
+ //! Called if the console gets closed
+ void IOConsole::exit()
+ {
+ // Exit is not an option, just do nothing (Shell doesn't really exit too)
+ }
+}
+
#ifdef ORXONOX_PLATFORM_UNIX
+// ###############################
+// ### Unix Implementation ###
+// ###############################
+
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#endif
namespace orxonox
{
- IOConsole* IOConsole::singletonPtr_s = NULL;
-
-#ifdef ORXONOX_PLATFORM_UNIX
-
namespace EscapeMode
{
enum Value
@@ -81,47 +142,37 @@
this->getTerminalSize();
this->lastTerminalWidth_ = this->terminalWidth_;
this->lastTerminalHeight_ = this->terminalHeight_;
+
+ // Disable standard std::cout logging
+ OutputHandler::getInstance().disableCout();
}
IOConsole::~IOConsole()
{
- // Goto last line and erase it
+ // Goto last line and create a new one
if (this->bStatusPrinted_)
std::cout << "\033[" << this->statusLineWidths_.size() << 'E';
- std::cout << "\033[1G\033[K";
- std::cout.flush();
+ std::cout << std::endl;
+
resetTerminalMode();
delete this->originalTerminalSettings_;
this->shell_->destroy();
- }
- void IOConsole::setTerminalMode()
- {
- termios new_settings;
-
- tcgetattr(0, this->originalTerminalSettings_);
- new_settings = *this->originalTerminalSettings_;
- new_settings.c_lflag &= ~(ICANON | ECHO);
- // new_settings.c_lflag |= ( ISIG | IEXTEN );
- new_settings.c_cc[VTIME] = 0;
- new_settings.c_cc[VMIN] = 0;
- tcsetattr(0, TCSANOW, &new_settings);
- COUT(0) << endl;
- // atexit(&IOConsole::resetTerminalMode);
+ // Enable standard std::cout logging again
+ OutputHandler::getInstance().enableCout();
}
- void IOConsole::resetTerminalMode()
- {
- tcsetattr(0, TCSANOW, IOConsole::originalTerminalSettings_);
- }
-
void IOConsole::update(const Clock& time)
{
unsigned char c = 0;
std::string escapeSequence;
EscapeMode::Value escapeMode = EscapeMode::None;
- while (read(STDIN_FILENO, &c, 1) == 1)
+ while (std::cin.good())
{
+ c = std::cin.get();
+ if (std::cin.bad())
+ break;
+
if (escapeMode == EscapeMode::First && (c == '[' || c=='O') )
escapeMode = EscapeMode::Second;
// Get Alt+Tab combination when switching applications
@@ -190,6 +241,8 @@
}
}
}
+ // Reset error flags in std::cin
+ std::cin.clear();
// If there is still an escape key pending (escape key ONLY), then
// it sure isn't an escape sequence anymore
@@ -204,7 +257,7 @@
int heightDiff = this->terminalHeight_ - this->lastTerminalHeight_;
if (this->bStatusPrinted_ && heightDiff < 0)
{
- // Terminal width has shrinked. The cursor will still be on the input line,
+ // Terminal width has shrunk. 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');
@@ -229,17 +282,9 @@
void IOConsole::printLogText(const std::string& text)
{
- std::string output;
+ std::string output = text;
+ int level = this->extractLogLevel(&output);
- // Handle line colouring by inspecting the first letter
- char level = 0;
- if (!text.empty())
- level = text[0];
- if (level >= -1 && level <= 6)
- output = text.substr(1);
- else
- output = text;
-
// Colour line
/*
switch (level)
@@ -296,13 +341,24 @@
this->bStatusPrinted_ = false;
}
- inline bool IOConsole::willPrintStatusLines()
+ void IOConsole::setTerminalMode()
{
- return !this->statusLineWidths_.empty()
- && this->terminalWidth_ >= this->statusLineMaxWidth_
- && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size());
+ termios new_settings;
+
+ tcgetattr(0, this->originalTerminalSettings_);
+ new_settings = *this->originalTerminalSettings_;
+ new_settings.c_lflag &= ~(ICANON | ECHO);
+ //new_settings.c_lflag |= (ISIG | IEXTEN);
+ new_settings.c_cc[VTIME] = 0;
+ new_settings.c_cc[VMIN] = 0;
+ tcsetattr(0, TCSANOW, &new_settings);
}
+ void IOConsole::resetTerminalMode()
+ {
+ tcsetattr(0, TCSANOW, IOConsole::originalTerminalSettings_);
+ }
+
void IOConsole::getTerminalSize()
{
#ifdef TIOCGSIZE
@@ -332,63 +388,11 @@
this->terminalHeight_ = 24;
}
-#elif defined(ORXONOX_PLATFORM_WINDOWS)
-
- IOConsole::IOConsole()
- : shell_(new Shell("IOConsole", false))
- , buffer_(shell_->getInputBuffer())
- {
- this->setTerminalMode();
- }
-
- IOConsole::~IOConsole()
- {
- }
-
- void IOConsole::setTerminalMode()
- {
- }
-
- void IOConsole::resetTerminalMode()
- {
- }
-
- void IOConsole::update(const Clock& time)
- {
- }
-
- void IOConsole::printLogText(const std::string& text)
- {
- }
-
- void IOConsole::printInputLine()
- {
- }
-
- void IOConsole::printStatusLines()
- {
- }
-
-#endif /* ORXONOX_PLATFORM_UNIX */
-
// ###############################
// ### ShellListener methods ###
// ###############################
- /**
- @brief
- Called if all output-lines have to be redrawn.
- */
- void IOConsole::linesChanged()
- {
- // Method only gets called upon start to draw all the lines
- // But we are using std::cout anyway, so do nothing here
- }
-
- /**
- @brief
- Called if only the last output-line has changed.
- */
+ //! Called if only the last output-line has changed
void IOConsole::onlyLastLineChanged()
{
// Save cursor position and move it to the beginning of the first output line
@@ -402,10 +406,7 @@
std::cout.flush();
}
- /**
- @brief
- Called if a new output-line was added.
- */
+ //! Called if a new output-line was added
void IOConsole::lineAdded()
{
// Move cursor to the bottom line
@@ -428,44 +429,114 @@
this->printStatusLines();
std::cout.flush();
}
+}
- /**
- @brief
- Called if the text in the input-line has changed.
- */
- void IOConsole::inputChanged()
+#elif defined(ORXONOX_PLATFORM_WINDOWS)
+// ##################################
+// ### Windows Implementation ###
+// ##################################
+
+namespace orxonox
+{
+ IOConsole::IOConsole()
+ : shell_(new Shell("IOConsole", false, true))
+ , buffer_(shell_->getInputBuffer())
+ , bStatusPrinted_(false)
+ , promptString_("orxonox # ")
{
- this->printInputLine();
- std::cout.flush();
+/*
+ this->setTerminalMode();
+ this->shell_->registerListener(this);
+
+ // Manually set the widths of the individual status lines
+ this->statusLineWidths_.push_back(29);
+ this->statusLineMaxWidth_ = 29;
+
+ this->getTerminalSize();
+ this->lastTerminalWidth_ = this->terminalWidth_;
+ this->lastTerminalHeight_ = this->terminalHeight_;
+
+ // Disable standard std::cout logging
+ OutputHandler::getInstance().disableCout();
+*/
}
- /**
- @brief
- Called if the position of the cursor in the input-line has changed.
- */
- void IOConsole::cursorChanged()
+ IOConsole::~IOConsole()
{
- this->printInputLine();
- std::cout.flush();
+/*
+ resetTerminalMode();
+ this->shell_->destroy();
+
+ // Enable standard std::cout logging again
+ OutputHandler::getInstance().enableCout();
+*/
}
- /**
- @brief
- Called if a command is about to be executed
- */
- void IOConsole::executed()
+ void IOConsole::update(const Clock& time)
{
- this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());
+/*
+ unsigned char c = 0;
+ while (std::cin.good())
+ {
+ c = std::cin.get();
+ if (std::cin.bad())
+ break;
+ }
+ // Reset error flags in std::cin
+ std::cin.clear();
+
+ // Determine terminal width and height
+ this->lastTerminalWidth_ = this->terminalWidth_;
+ this->lastTerminalHeight_ = this->terminalHeight_;
+ this->getTerminalSize();
+*/
}
+ void IOConsole::printLogText(const std::string& text)
+ {
+ }
- /**
- @brief
- Called if the console gets closed.
- */
- void IOConsole::exit()
+ void IOConsole::printInputLine()
{
- // Exit is not an option, IOConsole always exists
}
+ void IOConsole::printStatusLines()
+ {
+/*
+ if (this->willPrintStatusLines())
+ {
+ this->bStatusPrinted_ = true;
+ }
+ else
+ this->bStatusPrinted_ = false;
+*/
+ }
+
+ void IOConsole::setTerminalMode()
+ {
+ }
+
+ void IOConsole::resetTerminalMode()
+ {
+ }
+
+ void IOConsole::getTerminalSize()
+ {
+ }
+
+ // ###############################
+ // ### ShellListener methods ###
+ // ###############################
+
+ //! Called if only the last output-line has changed
+ void IOConsole::onlyLastLineChanged()
+ {
+ }
+
+ //! Called if a new output-line was added
+ void IOConsole::lineAdded()
+ {
+ }
}
+
+#endif /* ORXONOX_PLATFORM_UNIX */
Modified: code/branches/console/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.h 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/core/IOConsole.h 2009-11-02 16:54:13 UTC (rev 6015)
@@ -32,12 +32,14 @@
#include "CorePrereqs.h"
-#include <queue>
-#include <boost/scoped_ptr.hpp>
+#include <string>
+#include <vector>
#include "util/Singleton.h"
#include "core/Shell.h"
+#ifdef ORXONOX_PLATFORM_UNIX
struct termios;
+#endif
namespace orxonox
{
@@ -52,11 +54,11 @@
void update(const Clock& time);
private:
-
void setTerminalMode();
void resetTerminalMode();
void getTerminalSize();
bool willPrintStatusLines();
+ int extractLogLevel(std::string* text);
void printLogText(const std::string& line);
void printInputLine();
@@ -70,10 +72,8 @@
void cursorChanged();
void executed();
void exit();
-
Shell* shell_;
InputBuffer* buffer_;
- termios* originalTerminalSettings_;
unsigned int terminalWidth_;
unsigned int terminalHeight_;
unsigned int lastTerminalWidth_;
@@ -85,6 +85,10 @@
const std::string promptString_;
static const unsigned minOutputLines_ = 3;
+#ifdef ORXONOX_PLATFORM_UNIX
+ termios* originalTerminalSettings_;
+#endif
+
static IOConsole* singletonPtr_s;
};
}
Modified: code/branches/console/src/libraries/util/OutputHandler.cc
===================================================================
--- code/branches/console/src/libraries/util/OutputHandler.cc 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/util/OutputHandler.cc 2009-11-02 16:54:13 UTC (rev 6015)
@@ -120,6 +120,27 @@
};
+ /////////////////////////
+ ///// ConsoleWriter /////
+ /////////////////////////
+ /**
+ @brief
+ Writes the output to std::cout.
+ @note
+ This listener will usually be disable once an actual shell with console is instantiated.
+ */
+ class ConsoleWriter : public OutputListener
+ {
+ public:
+ //! Only assigns the output stream with std::cout
+ ConsoleWriter()
+ : OutputListener("consoleLog")
+ {
+ this->outputStream_ = &std::cout;
+ }
+ };
+
+
///////////////////////////
///// MemoryLogWriter /////
///////////////////////////
@@ -175,11 +196,23 @@
OutputHandler::OutputHandler()
: outputLevel_(OutputLevel::Verbose)
{
+#ifdef ORXONOX_RELEASE
+ const OutputLevel::Value defaultLevelConsole = OutputLevel::Error;
+ const OutputLevel::Value defaultLevelLogFile = OutputLevel::Info;
+#else
+ const OutputLevel::Value defaultLevelConsole = OutputLevel::Info;
+ const OutputLevel::Value defaultLevelLogFile = OutputLevel::Debug;
+#endif
+
this->logFile_ = new LogFileWriter();
// Use default level until we get the configValue from the Core
- this->logFile_->softDebugLevel_ = OutputLevel::Debug;
+ this->logFile_->softDebugLevel_ = defaultLevelLogFile;
this->registerOutputListener(this->logFile_);
+ this->consoleWriter_ = new ConsoleWriter();
+ this->consoleWriter_->softDebugLevel_ = defaultLevelConsole;
+ this->registerOutputListener(this->consoleWriter_);
+
this->output_ = new MemoryLogWriter();
// We capture as much input as the listener with the highest level
this->output_->softDebugLevel_ = getSoftDebugLevel();
@@ -224,6 +257,16 @@
this->logFile_->setLogPath(path);
}
+ void OutputHandler::disableCout()
+ {
+ this->unregisterOutputListener(this->consoleWriter_);
+ }
+
+ void OutputHandler::enableCout()
+ {
+ this->registerOutputListener(this->consoleWriter_);
+ }
+
OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const
{
return this->output_->output_.begin();
Modified: code/branches/console/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/console/src/libraries/util/OutputHandler.h 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/libraries/util/OutputHandler.h 2009-11-02 16:54:13 UTC (rev 6015)
@@ -73,6 +73,7 @@
// Forward declarations for classes in the source file
class LogFileWriter;
+ class ConsoleWriter;
class MemoryLogWriter;
/**
@@ -128,6 +129,10 @@
//! Set the log path once the program has been properly initialised
void setLogPath(const std::string& path);
+ //! Disables the std::cout stream for output
+ void disableCout();
+ //! Enables the std::cout stream for output (startup behaviour)
+ void enableCout();
//! Sets the level of the incoming output and returns the OutputHandler
inline OutputHandler& setOutputLevel(int level)
@@ -209,11 +214,12 @@
~OutputHandler();
OutputHandler(const OutputHandler& rhs); //! Unused and undefined
- std::list<OutputListener*> listeners_; //!< Array with all registered output listeners
- int outputLevel_; //!< The level of the incoming output
- LogFileWriter* logFile_; //!< Listener that writes to the log file
- MemoryLogWriter* output_; //!< Listener that Stores ALL output below the current soft debug level
- static int softDebugLevel_s; //!< Maximum of all soft debug levels. @note This is only static for faster access
+ std::list<OutputListener*> listeners_; //!< Array with all registered output listeners
+ int outputLevel_; //!< The level of the incoming output
+ LogFileWriter* logFile_; //!< Listener that writes to the log file
+ ConsoleWriter* consoleWriter_; //!< Listener for std::cout (just program beginning)
+ MemoryLogWriter* output_; //!< Listener that Stores ALL output below the current soft debug level
+ static int softDebugLevel_s; //!< Maximum of all soft debug levels. @note This is only static for faster access
};
/**
Modified: code/branches/console/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/orxonox/overlays/InGameConsole.cc 2009-11-02 16:54:13 UTC (rev 6015)
@@ -335,6 +335,14 @@
}
/**
+ @brief Called if a command is about to be executed
+ */
+ void InGameConsole::executed()
+ {
+ this->shell_->addOutputLine(this->shell_->getInput());
+ }
+
+ /**
@brief Called if the console gets closed.
*/
void InGameConsole::exit()
Modified: code/branches/console/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/branches/console/src/orxonox/overlays/InGameConsole.h 2009-11-02 12:57:19 UTC (rev 6014)
+++ code/branches/console/src/orxonox/overlays/InGameConsole.h 2009-11-02 16:54:13 UTC (rev 6015)
@@ -67,6 +67,7 @@
void lineAdded();
void inputChanged();
void cursorChanged();
+ void executed();
void exit();
void shiftLines();
More information about the Orxonox-commit
mailing list