[Orxonox-commit 1265] r5983 - in code/branches/console/src/libraries: core util

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Oct 21 22:25:59 CEST 2009


Author: rgrieder
Date: 2009-10-21 22:25:59 +0200 (Wed, 21 Oct 2009)
New Revision: 5983

Modified:
   code/branches/console/src/libraries/core/IOConsole.cc
   code/branches/console/src/libraries/core/IOConsole.h
   code/branches/console/src/libraries/core/Shell.cc
   code/branches/console/src/libraries/core/Shell.h
   code/branches/console/src/libraries/util/OutputHandler.cc
   code/branches/console/src/libraries/util/OutputHandler.h
Log:
IOConsole basically working though there are some unresolved issues and hacks. Note: Disabled std::cout output for the time being

Modified: code/branches/console/src/libraries/core/IOConsole.cc
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.cc	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/core/IOConsole.cc	2009-10-21 20:25:59 UTC (rev 5983)
@@ -61,6 +61,7 @@
     {
         this->originalTerminalSettings_ = new termios;
         this->setTerminalMode();
+		this->shell_.registerListener(this);
     }
 
     IOConsole::~IOConsole()
@@ -69,7 +70,6 @@
         std::cout.flush();
         resetTerminalMode();
         delete this->originalTerminalSettings_;
-        COUT(0) << "Press enter to end the game..." << std::endl;
     }
 
     void IOConsole::setTerminalMode()
@@ -107,7 +107,7 @@
             }
             else if (this->escapeMode_ == Second)
             {
-                bool endOfSeq = true;
+				this->escapeSequence_ += c;
                 this->escapeMode_ = None;
                 if      (this->escapeSequence_ == "A")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Up,       0, 0));
@@ -140,7 +140,7 @@
             {
                 if (this->escapeMode_ == First)
                 {
-                    this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0));
+                    this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, c, 0));
                     this->escapeMode_ = None;
                 }
                 if (c == '\033')
@@ -171,33 +171,32 @@
 
         // If there is still an escape key pending (escape key ONLY), then
         // it sure isn't an escape sequence here
-        this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0));
+        if (this->escapeMode_ == First)
+            this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0));
+        // Reset in any case because escape sequences always come in one piece
+        this->escapeMode_ = None;
 
         // Print input line
         this->printInputLine();
     }
 
-    void IOConsole::printOutputLine(const std::string& line)
+    void IOConsole::print(const std::string& text)
     {
-        COUT(0) << "print output" << std::endl;
-        // Save cursor position
-        std::cout << "\033[s";
-
         std::string output;
 
         // Handle line colouring by inspecting the first letter
         char level = 0;
-        if (!line.empty())
-            level = line[0];
+        if (!text.empty())
+            level = text[0];
         if (level >= -1 && level <= 6)
-            output = line.substr(1);
+            output = text.substr(1);
         else
-            output = line;
+            output = text;
 
         // Colour line
         switch (level)
         {
-        case -1: std::cout << "\033[30m"; break;
+        case -1: std::cout << "\033[37m"; break;
         case  1: std::cout << "\033[91m"; break;
         case  2: std::cout << "\033[31m"; break;
         case  3: std::cout << "\033[34m"; break;
@@ -208,25 +207,21 @@
         }
 
         // Print output line
-        std::cout << output << std::endl;
+        std::cout << output;
 
-        // Reset colour to black
-        std::cout << "\033[30m";
-        // Restore cursor position
-        std::cout << "\033[u";
+        // Reset colour to white
+        std::cout << "\033[37m";
         std::cout.flush();
-
-        this->printInputLine();
     }
 
     void IOConsole::printInputLine()
     {
         // set cursor to the beginning of the line and erase the line
-        std::cout << "\033[0G\033[K";
+        std::cout << "\033[1G\033[K";
         // print status line
         //std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
         // Show an arrow to indicate a command prompt
-        std::cout << ">";
+        std::cout << "orxonox>";
         // save cursor position
         std::cout << "\033[s";
         // print commandLine buffer
@@ -260,8 +255,14 @@
     */
     void IOConsole::onlyLastLineChanged()
     {
-        // We cannot do anything here because printed lines are fixed
-        COUT(2) << "Warning: Trying to edit last console lines, which is impossible!" << std::endl;
+		// Save cursor position and move it the beginning of the second to last line
+		std::cout << "\033[s\033[1F";
+		// Erase the second to last line
+		std::cout << "\033[K";
+		this->print(*(this->shell_.getNewestLineIterator()));
+		// Restore cursor
+		std::cout << "\033[u";
+		std::cout.flush();
     }
 
     /**
@@ -270,7 +271,11 @@
     */
     void IOConsole::lineAdded()
     {
-        this->printOutputLine(*(this->shell_.getNewestLineIterator()));
+		// Move curosr the beginning of the line and erase it
+		std::cout << "\033[1G\033[K";
+		this->print(*(this->shell_.getNewestLineIterator()));
+		std::cout << std::endl;
+		this->printInputLine();
     }
 
     /**
@@ -293,6 +298,20 @@
 
     /**
     @brief
+        Called if a command is about to be executed
+    */
+    void IOConsole::executed()
+    {
+		// Move curosr the beginning of the line
+		std::cout << "\033[1G";
+        // Print command so the user knows what he typed
+        std::cout << "orxonox>" << this->shell_.getInput() << std::endl;
+		this->printInputLine();
+    }
+
+
+    /**
+    @brief
         Called if the console gets closed.
     */
     void IOConsole::exit()

Modified: code/branches/console/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.h	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/core/IOConsole.h	2009-10-21 20:25:59 UTC (rev 5983)
@@ -62,7 +62,7 @@
         void setTerminalMode();
         static void resetTerminalMode();
 
-        void printOutputLine(const std::string& line);
+        void print(const std::string& line);
         void printInputLine();
 
         // Methods from ShellListener
@@ -71,6 +71,7 @@
         void lineAdded();
         void inputChanged();
         void cursorChanged();
+        void executed();
         void exit();
 
         Shell&                  shell_;

Modified: code/branches/console/src/libraries/core/Shell.cc
===================================================================
--- code/branches/console/src/libraries/core/Shell.cc	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/core/Shell.cc	2009-10-21 20:25:59 UTC (rev 5983)
@@ -120,9 +120,9 @@
         this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false);
         this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true);
         this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
-        this->inputBuffer_->registerListener(this, &Shell::backspace, static_cast<char>(127), true);
+        this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true);
         this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete);
-        this->inputBuffer_->registerListener(this, &Shell::exit, static_cast<char>(27), true);
+        this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape
         this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right);
         this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left);
         this->inputBuffer_->registerListener(this, &Shell::cursor_end, KeyCode::End);
@@ -277,7 +277,7 @@
     void Shell::execute()
     {
         this->addToHistory(this->inputBuffer_->get());
-        this->addLine(this->inputBuffer_->get(), 0);
+        this->updateListeners<&ShellListener::executed>();
 
         if (!CommandExecutor::execute(this->inputBuffer_->get()))
             this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);

Modified: code/branches/console/src/libraries/core/Shell.h
===================================================================
--- code/branches/console/src/libraries/core/Shell.h	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/core/Shell.h	2009-10-21 20:25:59 UTC (rev 5983)
@@ -56,6 +56,7 @@
             virtual void lineAdded() {}
             virtual void inputChanged() {}
             virtual void cursorChanged() {}
+            virtual void executed() {}
             virtual void exit() {}
     };
 

Modified: code/branches/console/src/libraries/util/OutputHandler.cc
===================================================================
--- code/branches/console/src/libraries/util/OutputHandler.cc	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/util/OutputHandler.cc	2009-10-21 20:25:59 UTC (rev 5983)
@@ -148,8 +148,8 @@
     */
     OutputHandler& OutputHandler::operator<<(std::streambuf* sb)
     {
-        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
-            std::cout << sb;
+        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
+        //    std::cout << sb;
 
         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
         {
@@ -170,8 +170,8 @@
     */
     OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&))
     {
-        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
-            manipulator(std::cout);
+        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
+        //    manipulator(std::cout);
 
         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
         {
@@ -192,8 +192,8 @@
     */
     OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&))
     {
-        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
-            manipulator(std::cout);
+        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
+        //    manipulator(std::cout);
 
         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
         {
@@ -214,8 +214,8 @@
     */
     OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
     {
-        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
-            manipulator(std::cout);
+        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
+        //    manipulator(std::cout);
 
         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
         {

Modified: code/branches/console/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/console/src/libraries/util/OutputHandler.h	2009-10-21 15:28:13 UTC (rev 5982)
+++ code/branches/console/src/libraries/util/OutputHandler.h	2009-10-21 20:25:59 UTC (rev 5983)
@@ -163,8 +163,8 @@
     template<class T>
     OutputHandler& OutputHandler::output(const T& output)
     {
-        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
-            std::cout << output;
+        //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
+        //    std::cout << output;
 
         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
         {
@@ -187,8 +187,8 @@
     template<class T>
     OutputHandler& operator<<(OutputHandler& out, const T& output)
     {
-        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
-            std::cout << output;
+        //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
+        //    std::cout << output;
 
         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel())
         {




More information about the Orxonox-commit mailing list