Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6010


Ignore:
Timestamp:
Oct 31, 2009, 11:13:52 PM (14 years ago)
Author:
rgrieder
Message:

Sorted out some small stuff in the Shell and hopefully fixed IOConsole problems (flickering and too much output).

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

Legend:

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

    r6007 r6010  
    5050{
    5151    IOConsole* IOConsole::singletonPtr_s = NULL;
    52     const std::string promptString_g = "orxonox>";
    5352
    5453#ifdef ORXONOX_PLATFORM_UNIX
     
    6564
    6665    IOConsole::IOConsole()
    67         : shell_(new Shell("IOConsole", false))
     66        : shell_(new Shell("IOConsole", false, true))
    6867        , buffer_(shell_->getInputBuffer())
    6968        , originalTerminalSettings_(new termios())
    7069        , bStatusPrinted_(false)
     70        , promptString_("orxonox> ")
    7171    {
    7272        this->setTerminalMode();
     
    143143                    this->buffer_->buttonPressed(KeyEvent(KeyCode::End,      0, 0));
    144144                else if (escapeSequence == "5~")
    145                     this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageUp,   0, 0));
     145                    this->buffer_->buttonPressed(KeyEvent(KeyCode::PageUp,   0, 0));
    146146                else if (escapeSequence == "6~")
    147                     this->buffer_->buttonPressed(KeyEvent(KeyCode::AltPageDown, 0, 0));
     147                    this->buffer_->buttonPressed(KeyEvent(KeyCode::PageDown, 0, 0));
    148148                else
    149149                    // Waiting for sequence to complete
     
    192192        this->printStatusLines();
    193193        this->printInputLine();
     194        std::cout.flush();
    194195    }
    195196
     
    227228        // Reset colour to white
    228229//        std::cout << "\033[37m";
    229         std::cout.flush();
    230230    }
    231231
     
    244244        if (this->buffer_->getCursorPosition() > 0)
    245245            std::cout << "\033[" << this->buffer_->getCursorPosition() << "C";
    246         std::cout.flush();
    247246    }
    248247
     
    259258            }
    260259            std::cout << "Status" << std::endl;
    261             std::cout.flush();
    262260            this->bStatusPrinted_ = true;
    263261        }
     
    332330    }
    333331
     332    void IOConsole::printStatusLines()
     333    {
     334    }
     335
    334336#endif /* ORXONOX_PLATFORM_UNIX */
    335337
     
    378380        this->printStatusLines();
    379381        this->printInputLine();
     382        std::cout.flush();
    380383    }
    381384
     
    387390    {
    388391        this->printInputLine();
     392        std::cout.flush();
    389393    }
    390394
     
    396400    {
    397401        this->printInputLine();
     402        std::cout.flush();
    398403    }
    399404
     
    404409    void IOConsole::executed()
    405410    {
    406         // Move cursor the beginning of the line
    407         std::cout << "\033[1G";
    408         // Print command so the user knows what he has typed
    409         std::cout << promptString_g << this->shell_->getInput() << std::endl;
    410         this->printInputLine();
     411        this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());
    411412    }
    412413
  • code/branches/console/src/libraries/core/IOConsole.h

    r6007 r6010  
    7777        std::vector<unsigned>   statusLineWidths_;
    7878        unsigned int            statusLineMaxWidth_;
     79        const std::string       promptString_;
    7980        static const unsigned   minOutputLines_ = 3;
    8081
  • code/branches/console/src/libraries/core/Shell.cc

    r6004 r6010  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    4444    SetConsoleCommandShortcut(OutputHandler, debug);
    4545
    46     Shell::Shell(const std::string& consoleName, bool bScrollable)
    47         : inputBuffer_(new InputBuffer())
    48         , OutputListener(consoleName)
     46    Shell::Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel)
     47        : OutputListener(consoleName)
     48        , inputBuffer_(new InputBuffer())
    4949        , consoleName_(consoleName)
     50        , bPrependOutputLevel_(bPrependOutputLevel)
    5051        , bScrollable_(bScrollable)
    5152    {
     
    5657        this->historyPosition_ = 0;
    5758        this->historyOffset_ = 0;
    58         this->finishedLastLine_ = true;
    59         this->bAddOutputLevel_ = false;
    60 
    61         this->clearLines();
     59        this->bFinishedLastLine_ = true;
     60
     61        this->clearOutput();
    6262        this->configureInputBuffer();
    6363
     
    131131    {
    132132        this->inputBuffer_->registerListener(this, &Shell::inputChanged, true);
    133         this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false);
    134         this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false);
    135         this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true);
    136         this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true);
    137         this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true);
    138         this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete);
    139         this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape
    140         this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right);
    141         this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left);
    142         this->inputBuffer_->registerListener(this, &Shell::cursor_end, KeyCode::End);
    143         this->inputBuffer_->registerListener(this, &Shell::cursor_home, KeyCode::Home);
    144         this->inputBuffer_->registerListener(this, &Shell::history_up, KeyCode::Up);
    145         this->inputBuffer_->registerListener(this, &Shell::history_down, KeyCode::Down);
    146         this->inputBuffer_->registerListener(this, &Shell::scroll_up, KeyCode::PageUp);
    147         this->inputBuffer_->registerListener(this, &Shell::scroll_down, KeyCode::PageDown);
    148         this->inputBuffer_->registerListener(this, &Shell::history_search_up, KeyCode::AltPageUp);
    149         this->inputBuffer_->registerListener(this, &Shell::history_search_down, KeyCode::AltPageDown);
     133        this->inputBuffer_->registerListener(this, &Shell::execute,         '\r',   false);
     134        this->inputBuffer_->registerListener(this, &Shell::execute,         '\n',   false);
     135        this->inputBuffer_->registerListener(this, &Shell::hintAndComplete, '\t',   true);
     136        this->inputBuffer_->registerListener(this, &Shell::backspace,       '\b',   true);
     137        this->inputBuffer_->registerListener(this, &Shell::backspace,       '\177', true);
     138        this->inputBuffer_->registerListener(this, &Shell::exit,            '\033', true); // escape
     139        this->inputBuffer_->registerListener(this, &Shell::deleteChar,      KeyCode::Delete);
     140        this->inputBuffer_->registerListener(this, &Shell::cursorRight,     KeyCode::Right);
     141        this->inputBuffer_->registerListener(this, &Shell::cursorLeft,      KeyCode::Left);
     142        this->inputBuffer_->registerListener(this, &Shell::cursorEnd,       KeyCode::End);
     143        this->inputBuffer_->registerListener(this, &Shell::cursorHome,      KeyCode::Home);
     144        this->inputBuffer_->registerListener(this, &Shell::historyUp,       KeyCode::Up);
     145        this->inputBuffer_->registerListener(this, &Shell::historyDown,     KeyCode::Down);
     146        if (this->bScrollable_)
     147        {
     148            this->inputBuffer_->registerListener(this, &Shell::scrollUp,    KeyCode::PageUp);
     149            this->inputBuffer_->registerListener(this, &Shell::scrollDown,  KeyCode::PageDown);
     150        }
     151        else
     152        {
     153            this->inputBuffer_->registerListener(this, &Shell::historySearchUp,   KeyCode::PageUp);
     154            this->inputBuffer_->registerListener(this, &Shell::historySearchDown, KeyCode::PageDown);
     155        }
    150156    }
    151157
     
    156162
    157163        for (unsigned int i = instance.historyOffset_; i < instance.commandHistory_.size(); ++i)
    158             instance.addLine(instance.commandHistory_[i], -1);
     164            instance.addOutputLine(instance.commandHistory_[i], -1);
    159165        for (unsigned int i =  0; i < instance.historyOffset_; ++i)
    160             instance.addLine(instance.commandHistory_[i], -1);
     166            instance.addOutputLine(instance.commandHistory_[i], -1);
    161167    }
    162168    */
     
    184190    }
    185191
    186     void Shell::setInput(const std::string& input)
    187     {
    188         this->inputBuffer_->set(input);
    189         this->inputChanged();
    190     }
    191 
    192     void Shell::addLine(const std::string& line, int level)
     192    void Shell::addOutputLine(const std::string& line, int level)
    193193    {
    194194        if (level <= this->softDebugLevel_)
     
    197197    }
    198198
    199     void Shell::clearLines()
     199    void Shell::clearOutput()
    200200    {
    201201        this->outputLines_.clear();
     
    203203
    204204        this->scrollPosition_ = 0;
    205         this->finishedLastLine_ = true;
     205        this->bFinishedLastLine_ = true;
    206206
    207207        this->updateListeners<&ShellListener::linesChanged>();
     
    256256                break;
    257257
    258             if (this->finishedLastLine_)
     258            if (this->bFinishedLastLine_)
    259259            {
    260                 if (this->bAddOutputLevel_)
     260                if (this->bPrependOutputLevel_)
    261261                    output.insert(0, 1, static_cast<char>(level));
    262262
     
    268268                    this->scrollIterator_ = this->outputLines_.begin();
    269269
    270                 this->finishedLastLine_ = newline;
     270                this->bFinishedLastLine_ = newline;
    271271
    272272                if (!this->scrollPosition_)
     
    278278            {
    279279                (*this->outputLines_.begin()) += output;
    280                 this->finishedLastLine_ = newline;
     280                this->bFinishedLastLine_ = newline;
    281281                this->updateListeners<&ShellListener::onlyLastLineChanged>();
    282282            }
     
    285285    }
    286286
    287     void Shell::inputChanged()
    288     {
    289         this->updateListeners<&ShellListener::inputChanged>();
    290         this->updateListeners<&ShellListener::cursorChanged>();
    291     }
    292 
    293     void Shell::execute()
    294     {
    295         this->addToHistory(this->inputBuffer_->get());
    296         this->updateListeners<&ShellListener::executed>();
    297 
    298         if (!CommandExecutor::execute(this->inputBuffer_->get()))
    299             this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
    300 
    301         this->clear();
    302     }
    303 
    304     void Shell::hintandcomplete()
    305     {
    306         this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get()));
    307         this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
    308 
    309         this->inputChanged();
    310     }
    311 
    312     void Shell::backspace()
    313     {
    314         this->inputBuffer_->removeBehindCursor();
    315         this->updateListeners<&ShellListener::inputChanged>();
    316         this->updateListeners<&ShellListener::cursorChanged>();
    317     }
    318 
    319     void Shell::deletechar()
    320     {
    321         this->inputBuffer_->removeAtCursor();
    322         this->updateListeners<&ShellListener::inputChanged>();
    323     }
    324 
    325     void Shell::clear()
     287    void Shell::clearInput()
    326288    {
    327289        this->inputBuffer_->clear();
     
    331293    }
    332294
    333     void Shell::cursor_right()
     295    void Shell::setPromptPrefix(const std::string& str)
     296    {
     297    }
     298
     299
     300    // ##########################################
     301    // ###   InputBuffer callback functions   ###
     302    // ##########################################
     303
     304    void Shell::inputChanged()
     305    {
     306        this->updateListeners<&ShellListener::inputChanged>();
     307        this->updateListeners<&ShellListener::cursorChanged>();
     308    }
     309
     310    void Shell::execute()
     311    {
     312        this->addToHistory(this->inputBuffer_->get());
     313        this->updateListeners<&ShellListener::executed>();
     314
     315        if (!CommandExecutor::execute(this->inputBuffer_->get()))
     316            this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1);
     317
     318        this->clearInput();
     319    }
     320
     321    void Shell::hintAndComplete()
     322    {
     323        this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get()));
     324        this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1);
     325
     326        this->inputChanged();
     327    }
     328
     329    void Shell::backspace()
     330    {
     331        this->inputBuffer_->removeBehindCursor();
     332        this->updateListeners<&ShellListener::inputChanged>();
     333        this->updateListeners<&ShellListener::cursorChanged>();
     334    }
     335
     336    void Shell::exit()
     337    {
     338        if (this->inputBuffer_->getSize() > 0)
     339        {
     340            this->clearInput();
     341            return;
     342        }
     343
     344        this->clearInput();
     345        this->scrollPosition_ = 0;
     346        this->scrollIterator_ = this->outputLines_.begin();
     347
     348        this->updateListeners<&ShellListener::exit>();
     349    }
     350
     351    void Shell::deleteChar()
     352    {
     353        this->inputBuffer_->removeAtCursor();
     354        this->updateListeners<&ShellListener::inputChanged>();
     355    }
     356
     357    void Shell::cursorRight()
    334358    {
    335359        this->inputBuffer_->increaseCursor();
     
    337361    }
    338362
    339     void Shell::cursor_left()
     363    void Shell::cursorLeft()
    340364    {
    341365        this->inputBuffer_->decreaseCursor();
     
    343367    }
    344368
    345     void Shell::cursor_end()
     369    void Shell::cursorEnd()
    346370    {
    347371        this->inputBuffer_->setCursorToEnd();
     
    349373    }
    350374
    351     void Shell::cursor_home()
     375    void Shell::cursorHome()
    352376    {
    353377        this->inputBuffer_->setCursorToBegin();
     
    355379    }
    356380
    357     void Shell::history_up()
     381    void Shell::historyUp()
    358382    {
    359383        if (this->historyPosition_ < this->commandHistory_.size())
     
    364388    }
    365389
    366     void Shell::history_down()
     390    void Shell::historyDown()
    367391    {
    368392        if (this->historyPosition_ > 0)
     
    373397    }
    374398
    375     void Shell::history_search_up()
     399    void Shell::historySearchUp()
    376400    {
    377401        if (this->historyPosition_ == this->historyOffset_)
    378402            return;
    379403        unsigned int cursorPosition = this->getCursorPosition();
    380         std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline untill the cursor position
     404        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until the cursor position
    381405        for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++)
    382406        {
     
    391415    }
    392416
    393     void Shell::history_search_down()
     417    void Shell::historySearchDown()
    394418    {
    395419        if (this->historyPosition_ == 0)
    396420            return;
    397421        unsigned int cursorPosition = this->getCursorPosition();
    398         std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn$
     422        std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning
    399423        for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--)
    400424        {
     
    409433    }
    410434
    411     void Shell::scroll_up()
     435    void Shell::scrollUp()
    412436    {
    413437        if (this->scrollIterator_ != this->outputLines_.end())
     
    420444    }
    421445
    422     void Shell::scroll_down()
     446    void Shell::scrollDown()
    423447    {
    424448        if (this->scrollIterator_ != this->outputLines_.begin())
     
    430454        }
    431455    }
    432 
    433     void Shell::exit()
    434     {
    435         if (this->inputBuffer_->getSize() > 0)
    436         {
    437             this->clear();
    438             return;
    439         }
    440 
    441         this->clear();
    442         this->scrollPosition_ = 0;
    443         this->scrollIterator_ = this->outputLines_.begin();
    444 
    445         this->updateListeners<&ShellListener::exit>();
    446     }
    447456}
  • code/branches/console/src/libraries/core/Shell.h

    r6004 r6010  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    6161    };
    6262
     63
    6364    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
    6465    {
    6566        public:
    66             Shell(const std::string& consoleName, bool bScrollable);
    67             virtual ~Shell();
     67            Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false);
     68            ~Shell();
    6869
    6970            void setConfigValues();
     
    8182                { return this->inputBuffer_->getCursorPosition(); }
    8283
    83             void setInput(const std::string& input);
    84 
    85             inline void clearInput()
    86                 { this->setInput(""); }
    8784            inline std::string getInput() const
    8885                { return this->inputBuffer_->get(); }
     
    9188            std::list<std::string>::const_iterator getEndIterator() const;
    9289
    93             void addLine(const std::string& line, int level = 0);
    94             void clearLines();
     90            void addOutputLine(const std::string& line, int level = 0);
     91            void clearOutput();
    9592
    9693            inline unsigned int getNumLines() const
     
    9996                { return this->scrollPosition_; }
    10097
    101             inline void addOutputLevel(bool bAddOutputLevel)
    102                 { this->bAddOutputLevel_ = bAddOutputLevel; }
     98            inline const std::string& getPromptPrefix() const { return this->promptPrefix_; }
     99            void setPromptPrefix(const std::string& str);
    103100
    104101        private:
    105102            Shell(const Shell& other);
    106103
     104            void addToHistory(const std::string& command);
     105            std::string getFromHistory() const;
     106            void clearInput();
     107            // OutputListener
     108            void outputChanged(int level);
     109
    107110            void configureInputBuffer();
    108111
    109             void addToHistory(const std::string& command);
    110             std::string getFromHistory() const;
    111 
    112             virtual void outputChanged(int level);
    113 
     112            // InputBuffer callbacks
    114113            void inputChanged();
    115114            void execute();
    116             void hintandcomplete();
     115            void hintAndComplete();
    117116            void backspace();
    118             void deletechar();
    119             void clear();
    120             void cursor_right();
    121             void cursor_left();
    122             void cursor_end();
    123             void cursor_home();
    124             void history_up();
    125             void history_down();
    126             void history_search_up();
    127             void history_search_down();
    128             void scroll_up();
    129             void scroll_down();
     117            void deleteChar();
     118            void cursorRight();
     119            void cursorLeft();
     120            void cursorEnd();
     121            void cursorHome();
     122            void historyUp();
     123            void historyDown();
     124            void historySearchUp();
     125            void historySearchDown();
     126            void scrollUp();
     127            void scrollDown();
    130128            void exit();
    131129
     
    138136
    139137            std::list<ShellListener*> listeners_;
    140             InputBuffer* inputBuffer_;
    141             std::stringstream outputBuffer_;
    142             bool finishedLastLine_;
    143             std::list<std::string> outputLines_;
     138            InputBuffer*              inputBuffer_;
     139            std::stringstream         outputBuffer_;
     140            bool                      bFinishedLastLine_;
     141            std::list<std::string>    outputLines_;
    144142            std::list<std::string>::const_iterator scrollIterator_;
    145             unsigned int scrollPosition_;
    146             unsigned int historyPosition_;
    147             bool bAddOutputLevel_;
    148             ConfigFileType commandHistoryConfigFileType_;
    149             const std::string consoleName_;
    150             const bool bScrollable_;
     143            unsigned int              scrollPosition_;
     144            unsigned int              historyPosition_;
     145            ConfigFileType            commandHistoryConfigFileType_;
     146
     147            std::string               promptPrefix_;
     148            const std::string         consoleName_;
     149            const bool                bPrependOutputLevel_;
     150            const bool                bScrollable_;
    151151
    152152            // Config values
    153             unsigned int maxHistoryLength_;
    154             unsigned int historyOffset_;
    155             std::vector<std::string> commandHistory_;
    156             int softDebugLevel_;
     153            unsigned int              maxHistoryLength_;
     154            unsigned int              historyOffset_;
     155            std::vector<std::string>  commandHistory_;
     156            int                       softDebugLevel_;
    157157    };
    158158}
  • code/branches/console/src/libraries/core/input/InputPrereqs.h

    r5986 r6010  
    179179            Up            = OIS::KC_UP,              // UpArrow on arrow keypad
    180180            PageUp        = OIS::KC_PGUP,            // PgUp on arrow keypad
    181             AltPageUp     = OIS::KC_PGUP+1,          // Alternative PgUp for the IOConsole
    182181            Left          = OIS::KC_LEFT,            // LeftArrow on arrow keypad
    183182            Right         = OIS::KC_RIGHT,           // RightArrow on arrow keypad
     
    185184            Down          = OIS::KC_DOWN,            // DownArrow on arrow keypad
    186185            PageDown      = OIS::KC_PGDOWN,          // PgDn on arrow keypad
    187             AltPageDown   = OIS::KC_END-1,           // Alternative PgUp for IOConsole
    188186            Insert        = OIS::KC_INSERT,          // Insert on arrow keypad
    189187            Delete        = OIS::KC_DELETE,          // Delete on arrow keypad
     
    288286            "UP",
    289287            "PageUp",
    290             "", // used for AltPageUp
     288            "",
    291289            "Left",
    292290            "",
    293291            "Right",
    294             "", // used for AltPageDown
     292            "",
    295293            "End", "Down", "PageDown", "Insert", "Delete",
    296294            "","","","","","","",
  • code/branches/console/src/orxonox/overlays/InGameConsole.cc

    r6004 r6010  
    6868    */
    6969    InGameConsole::InGameConsole()
    70         : shell_(new Shell("InGameConsole", true))
     70        : shell_(new Shell("InGameConsole", true, true))
    7171        , consoleOverlay_(0)
    7272        , consoleOverlayContainer_(0)
     
    255255        // we take -1.2 because the border makes the panel bigger
    256256        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
    257 
    258         this->shell_->addOutputLevel(true);
    259257
    260258        COUT(4) << "Info: InGameConsole initialized" << std::endl;
Note: See TracChangeset for help on using the changeset viewer.