Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 21, 2009, 10:25:59 PM (15 years ago)
Author:
rgrieder
Message:

IOConsole basically working though there are some unresolved issues and hacks. Note: Disabled std::cout output for the time being

Location:
code/branches/console/src/libraries
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/libraries/core/IOConsole.cc

    r5975 r5983  
    6262        this->originalTerminalSettings_ = new termios;
    6363        this->setTerminalMode();
     64                this->shell_.registerListener(this);
    6465    }
    6566
     
    7071        resetTerminalMode();
    7172        delete this->originalTerminalSettings_;
    72         COUT(0) << "Press enter to end the game..." << std::endl;
    7373    }
    7474
     
    108108            else if (this->escapeMode_ == Second)
    109109            {
    110                 bool endOfSeq = true;
     110                                this->escapeSequence_ += c;
    111111                this->escapeMode_ = None;
    112112                if      (this->escapeSequence_ == "A")
     
    141141                if (this->escapeMode_ == First)
    142142                {
    143                     this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0));
     143                    this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, c, 0));
    144144                    this->escapeMode_ = None;
    145145                }
     
    172172        // If there is still an escape key pending (escape key ONLY), then
    173173        // it sure isn't an escape sequence here
    174         this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0));
     174        if (this->escapeMode_ == First)
     175            this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0));
     176        // Reset in any case because escape sequences always come in one piece
     177        this->escapeMode_ = None;
    175178
    176179        // Print input line
     
    178181    }
    179182
    180     void IOConsole::printOutputLine(const std::string& line)
    181     {
    182         COUT(0) << "print output" << std::endl;
    183         // Save cursor position
    184         std::cout << "\033[s";
    185 
     183    void IOConsole::print(const std::string& text)
     184    {
    186185        std::string output;
    187186
    188187        // Handle line colouring by inspecting the first letter
    189188        char level = 0;
    190         if (!line.empty())
    191             level = line[0];
     189        if (!text.empty())
     190            level = text[0];
    192191        if (level >= -1 && level <= 6)
    193             output = line.substr(1);
     192            output = text.substr(1);
    194193        else
    195             output = line;
     194            output = text;
    196195
    197196        // Colour line
    198197        switch (level)
    199198        {
    200         case -1: std::cout << "\033[30m"; break;
     199        case -1: std::cout << "\033[37m"; break;
    201200        case  1: std::cout << "\033[91m"; break;
    202201        case  2: std::cout << "\033[31m"; break;
     
    209208
    210209        // Print output line
    211         std::cout << output << std::endl;
    212 
    213         // Reset colour to black
    214         std::cout << "\033[30m";
    215         // Restore cursor position
    216         std::cout << "\033[u";
     210        std::cout << output;
     211
     212        // Reset colour to white
     213        std::cout << "\033[37m";
    217214        std::cout.flush();
    218 
    219         this->printInputLine();
    220215    }
    221216
     
    223218    {
    224219        // set cursor to the beginning of the line and erase the line
    225         std::cout << "\033[0G\033[K";
     220        std::cout << "\033[1G\033[K";
    226221        // print status line
    227222        //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 # ";
    228223        // Show an arrow to indicate a command prompt
    229         std::cout << ">";
     224        std::cout << "orxonox>";
    230225        // save cursor position
    231226        std::cout << "\033[s";
     
    261256    void IOConsole::onlyLastLineChanged()
    262257    {
    263         // We cannot do anything here because printed lines are fixed
    264         COUT(2) << "Warning: Trying to edit last console lines, which is impossible!" << std::endl;
     258                // Save cursor position and move it the beginning of the second to last line
     259                std::cout << "\033[s\033[1F";
     260                // Erase the second to last line
     261                std::cout << "\033[K";
     262                this->print(*(this->shell_.getNewestLineIterator()));
     263                // Restore cursor
     264                std::cout << "\033[u";
     265                std::cout.flush();
    265266    }
    266267
     
    271272    void IOConsole::lineAdded()
    272273    {
    273         this->printOutputLine(*(this->shell_.getNewestLineIterator()));
     274                // Move curosr the beginning of the line and erase it
     275                std::cout << "\033[1G\033[K";
     276                this->print(*(this->shell_.getNewestLineIterator()));
     277                std::cout << std::endl;
     278                this->printInputLine();
    274279    }
    275280
     
    294299    /**
    295300    @brief
     301        Called if a command is about to be executed
     302    */
     303    void IOConsole::executed()
     304    {
     305                // Move curosr the beginning of the line
     306                std::cout << "\033[1G";
     307        // Print command so the user knows what he typed
     308        std::cout << "orxonox>" << this->shell_.getInput() << std::endl;
     309                this->printInputLine();
     310    }
     311
     312
     313    /**
     314    @brief
    296315        Called if the console gets closed.
    297316    */
  • code/branches/console/src/libraries/core/IOConsole.h

    r5975 r5983  
    6363        static void resetTerminalMode();
    6464
    65         void printOutputLine(const std::string& line);
     65        void print(const std::string& line);
    6666        void printInputLine();
    6767
     
    7272        void inputChanged();
    7373        void cursorChanged();
     74        void executed();
    7475        void exit();
    7576
  • code/branches/console/src/libraries/core/Shell.cc

    r5973 r5983  
    121121        this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true);
    122122        this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
    123         this->inputBuffer_->registerListener(this, &Shell::backspace, static_cast<char>(127), true);
     123        this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true);
    124124        this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete);
    125         this->inputBuffer_->registerListener(this, &Shell::exit, static_cast<char>(27), true);
     125        this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape
    126126        this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right);
    127127        this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left);
     
    278278    {
    279279        this->addToHistory(this->inputBuffer_->get());
    280         this->addLine(this->inputBuffer_->get(), 0);
     280        this->updateListeners<&ShellListener::executed>();
    281281
    282282        if (!CommandExecutor::execute(this->inputBuffer_->get()))
  • code/branches/console/src/libraries/core/Shell.h

    r5969 r5983  
    5757            virtual void inputChanged() {}
    5858            virtual void cursorChanged() {}
     59            virtual void executed() {}
    5960            virtual void exit() {}
    6061    };
  • code/branches/console/src/libraries/util/OutputHandler.cc

    r5738 r5983  
    149149    OutputHandler& OutputHandler::operator<<(std::streambuf* sb)
    150150    {
    151         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    152             std::cout << sb;
     151        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     152        //    std::cout << sb;
    153153
    154154        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     
    171171    OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&))
    172172    {
    173         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    174             manipulator(std::cout);
     173        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     174        //    manipulator(std::cout);
    175175
    176176        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     
    193193    OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&))
    194194    {
    195         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    196             manipulator(std::cout);
     195        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     196        //    manipulator(std::cout);
    197197
    198198        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     
    215215    OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
    216216    {
    217         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    218             manipulator(std::cout);
     217        //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     218        //    manipulator(std::cout);
    219219
    220220        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
  • code/branches/console/src/libraries/util/OutputHandler.h

    r5738 r5983  
    164164    OutputHandler& OutputHandler::output(const T& output)
    165165    {
    166         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    167             std::cout << output;
     166        //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     167        //    std::cout << output;
    168168
    169169        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     
    188188    OutputHandler& operator<<(OutputHandler& out, const T& output)
    189189    {
    190         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
    191             std::cout << output;
     190        //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
     191        //    std::cout << output;
    192192
    193193        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel())
Note: See TracChangeset for help on using the changeset viewer.