[Orxonox-commit 1255] r5973 - in code/branches/console/src: . libraries/core orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Tue Oct 20 22:32:07 CEST 2009


Author: rgrieder
Date: 2009-10-20 22:32:06 +0200 (Tue, 20 Oct 2009)
New Revision: 5973

Modified:
   code/branches/console/src/CMakeLists.txt
   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/core/Shell.cc
   code/branches/console/src/orxonox/gamestates/GSIOConsole.cc
Log:
Input part of the IOConsole should be working (at least with SSH on tardis). Note: removed modules from compilation

Modified: code/branches/console/src/CMakeLists.txt
===================================================================
--- code/branches/console/src/CMakeLists.txt	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/CMakeLists.txt	2009-10-20 20:32:06 UTC (rev 5973)
@@ -97,7 +97,7 @@
 ADD_SUBDIRECTORY(external)
 ADD_SUBDIRECTORY(libraries)
 ADD_SUBDIRECTORY(orxonox)
-ADD_SUBDIRECTORY(modules)
+#ADD_SUBDIRECTORY(modules)
 
 ################ Executable ################
 

Modified: code/branches/console/src/libraries/core/Core.cc
===================================================================
--- code/branches/console/src/libraries/core/Core.cc	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/libraries/core/Core.cc	2009-10-20 20:32:06 UTC (rev 5973)
@@ -63,6 +63,7 @@
 #include "GUIManager.h"
 #include "Identifier.h"
 #include "Language.h"
+#include "IOConsole.h"
 #include "LuaState.h"
 #include "ScopedSingletonManager.h"
 #include "Shell.h"
@@ -264,6 +265,8 @@
 
         // create a shell
         this->shell_.reset(new Shell());
+        // create persistent io console
+        this->ioConsole_.reset(new IOConsole());
 
         // Create singletons that always exist (in other libraries)
         this->rootScope_.reset(new Scope<ScopeID::Root>());
@@ -443,6 +446,8 @@
             // graphics singletons from other libraries
             ScopedSingletonManager::update<ScopeID::Graphics>(time);
         }
+        // process console text
+        this->ioConsole_->update(time);
         // process thread commands
         this->tclThreadManager_->update(time);
     }

Modified: code/branches/console/src/libraries/core/Core.h
===================================================================
--- code/branches/console/src/libraries/core/Core.h	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/libraries/core/Core.h	2009-10-20 20:32:06 UTC (rev 5973)
@@ -42,6 +42,7 @@
 namespace orxonox
 {
     class CoreConfiguration;
+	class IOConsole;
 
     /**
     @brief
@@ -96,6 +97,7 @@
             scoped_ptr<TclBind>           tclBind_;
             scoped_ptr<TclThreadManager>  tclThreadManager_;
             scoped_ptr<Shell>             shell_;
+            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-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/libraries/core/IOConsole.cc	2009-10-20 20:32:06 UTC (rev 5973)
@@ -56,12 +56,8 @@
 
     IOConsole::IOConsole()
         : shell_(Shell::getInstance())
-        , cleanLine_(true)
         , bEscapeMode_(false)
         , buffer_(Shell::getInstance().getInputBuffer())
-        , inputIterator_(0)
-        , cursorX_(0)
-        , cursorY_(0)
     {
         this->originalTerminalSettings_ = new termios;
         this->setTerminalMode();
@@ -80,13 +76,13 @@
     {
         termios new_settings;
 
-        tcgetattr(0,this->originalTerminalSettings_);
+        tcgetattr(0, this->originalTerminalSettings_);
         new_settings = *this->originalTerminalSettings_;
-        new_settings.c_lflag &= ~( ICANON | ECHO );
+        new_settings.c_lflag &= ~(ICANON | ECHO);
         //         new_settings.c_lflag |= ( ISIG | IEXTEN );
         new_settings.c_cc[VTIME] = 1;
-        new_settings.c_cc[VMIN] = 0;
-        tcsetattr(0,TCSANOW,&new_settings);
+        new_settings.c_cc[VMIN]  = 0;
+        tcsetattr(0, TCSANOW, &new_settings);
         COUT(0) << endl;
         //       atexit(&IOConsole::resetTerminalMode);
     }
@@ -98,16 +94,14 @@
 
     void IOConsole::update(const Clock& time)
     {
-        unsigned c;
+        unsigned char c;
         while (read(STDIN_FILENO, &c, 1) == 1)
         {
             if (this->bEscapeMode_)
             {
                 this->escapeSequence_ += c;
-                bool clear = true;
-                if      (this->escapeSequence_ == "\033")
-                    this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape,   0, 0));
-                else if (this->escapeSequence_ == "[A")
+                bool endOfSeq = true;
+                if      (this->escapeSequence_ == "[A")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Up,       0, 0));
                 else if (this->escapeSequence_ == "[B")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Down,     0, 0));
@@ -119,6 +113,8 @@
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Home,     0, 0));
                 else if (this->escapeSequence_ == "[2~")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Insert,   0, 0));
+                else if (this->escapeSequence_ == "[3~")
+                    this->buffer_->buttonPressed(KeyEvent(KeyCode::Delete,   0, 0));
                 else if (this->escapeSequence_ == "[4~")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::End,      0, 0));
                 else if (this->escapeSequence_ == "[5~")
@@ -129,24 +125,30 @@
                 else if (this->escapeSequence_ == "\t")
                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Tab, '\t', KeyboardModifier::Alt));
                 else if (this->escapeSequence_.size() > 4)
-                    clear = true; // Something went wrong, start over
+                    endOfSeq = true; // Something went wrong, start over
                 else
-                    clear = false;
+                    endOfSeq = false;
 
-                if (clear)
-                    this->escapeSequence_.clear();
+                //this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape,   0, 0));
+
+                if (endOfSeq)
+                    this->bEscapeMode_ = false;
             }
             else // not in an escape sequence
             {
                 if (c == '\033')
+				{
                     this->bEscapeMode_ = true;
+					this->escapeSequence_.clear();
+				}
                 else
                 {
                     KeyCode::ByEnum code;
                     switch (c)
                     {
                     case '\n': code = KeyCode::Return; break;
-                    case  127: code = KeyCode::Delete; break; 
+                    case '\r': code = KeyCode::Return; break;
+                    case  127: code = KeyCode::Back;   break; 
                     case '\b': code = KeyCode::Back;   break;
                     case '\t': code = KeyCode::Tab;    break;
                     default:
@@ -159,10 +161,14 @@
                 }
             }
         }
+
+		// Print input line
+		this->printInputLine();
     }
 
     void IOConsole::printOutputLine(const std::string& line)
     {
+		COUT(0) << "print output" << std::endl;
         // Save cursor position
         std::cout << "\033[s";
 
@@ -198,6 +204,8 @@
         // Restore cursor position
         std::cout << "\033[u";
         std::cout.flush();
+
+		this->printInputLine();
     }
 
     void IOConsole::printInputLine()
@@ -205,12 +213,14 @@
         // set cursor to the beginning of the line and erase the line
         std::cout << "\033[0G\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 # ";
+        //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 << ">";
         // save cursor position
         std::cout << "\033[s";
         // print commandLine buffer
         std::cout << this->shell_.getInput();
-        // restore cursor position and move it cursorX_ to the right
+        // restore cursor position and move it to the right
         std::cout << "\033[u";
         if (this->buffer_->getCursorPosition() > 0)
             std::cout << "\033[" << this->buffer_->getCursorPosition() << "C";

Modified: code/branches/console/src/libraries/core/IOConsole.h
===================================================================
--- code/branches/console/src/libraries/core/IOConsole.h	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/libraries/core/IOConsole.h	2009-10-20 20:32:06 UTC (rev 5973)
@@ -57,8 +57,6 @@
 
         void printOutputLine(const std::string& line);
         void printInputLine();
-        void insertCharacter(unsigned int position, char c);
-        void deleteCharacter(unsigned int position);
 
         // Methods from ShellListener
         void linesChanged();
@@ -69,17 +67,11 @@
         void exit();
 
         Shell&                  shell_;
-        bool                    cleanLine_;
         bool                    bEscapeMode_;
         std::string             escapeSequence_;
         InputBuffer*            buffer_;
-        unsigned char*          commandLine_;
-        unsigned int            inputIterator_;
         static termios*         originalTerminalSettings_;
 
-        unsigned int            cursorX_;
-        unsigned int            cursorY_;
-
         static IOConsole* singletonPtr_s;
     };
 }

Modified: code/branches/console/src/libraries/core/Shell.cc
===================================================================
--- code/branches/console/src/libraries/core/Shell.cc	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/libraries/core/Shell.cc	2009-10-20 20:32:06 UTC (rev 5973)
@@ -117,8 +117,10 @@
     {
         this->inputBuffer_->registerListener(this, &Shell::inputChanged, true);
         this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
+        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::deletechar, KeyCode::Delete);
         this->inputBuffer_->registerListener(this, &Shell::exit, static_cast<char>(27), true);
         this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right);

Modified: code/branches/console/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/branches/console/src/orxonox/gamestates/GSIOConsole.cc	2009-10-20 17:08:05 UTC (rev 5972)
+++ code/branches/console/src/orxonox/gamestates/GSIOConsole.cc	2009-10-20 20:32:06 UTC (rev 5973)
@@ -57,10 +57,12 @@
 
     void GSIOConsole::update(const Clock& time)
     {
+		/*
         std::cout << ">";
         std::string command;
         std::getline(std::cin, command);
         CommandExecutor::execute(command, true);
+		*/
     }
 
     void GSIOConsole::loadMenu()




More information about the Orxonox-commit mailing list