Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 22, 2009, 11:32:30 PM (15 years ago)
Author:
scheusso
Message:

added a new feature to the IOConsole: you can now search the history (like in bash shells) with PgUP
just enter a few signs/characters of a command you once typed in and press PgUP to complete the command
if the found command is not the one you were looking for just press PgUP again

File:
1 edited

Legend:

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

    r5983 r5986  
    3030
    3131#include "util/OutputHandler.h"
     32#include "util/StringUtils.h"
    3233#include "CommandExecutor.h"
    3334#include "CoreIncludes.h"
     
    132133        this->inputBuffer_->registerListener(this, &Shell::scroll_up, KeyCode::PageUp);
    133134        this->inputBuffer_->registerListener(this, &Shell::scroll_down, KeyCode::PageDown);
     135        this->inputBuffer_->registerListener(this, &Shell::history_search_up, KeyCode::AltPageUp);
     136        this->inputBuffer_->registerListener(this, &Shell::history_search_down, KeyCode::AltPageDown);
    134137    }
    135138
     
    357360    }
    358361
     362    void Shell::history_search_up()
     363    {
     364        if (this->historyPosition_ == this->historyOffset_)
     365            return;
     366        unsigned int cursorPosition = this->getCursorPosition();
     367        std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginning of the inputline untill the cursor position
     368        for (unsigned int newPos = this->historyPosition_+1; newPos<=this->historyOffset_; newPos++)
     369        {
     370            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //search case insensitive
     371            {
     372                this->historyPosition_ = newPos;
     373                this->inputBuffer_->set(this->getFromHistory());
     374                this->setCursorPosition( cursorPosition );
     375                return;
     376            }
     377        }
     378    }
     379
     380    void Shell::history_search_down()
     381    {
     382        if (this->historyPosition_ == 0)
     383            return;
     384        unsigned int cursorPosition = this->getCursorPosition();
     385        std::string input_str( this->getInput().substr(0,cursorPosition) ); //only search for the expression from the beginn$
     386        for (unsigned int newPos = this->historyPosition_-1; newPos>0; newPos--)
     387        {
     388            if (getLowercase(this->commandHistory_[this->historyOffset_ - newPos]).find(getLowercase(input_str)) == 0) //sear$
     389            {
     390                this->historyPosition_ = newPos;
     391                this->inputBuffer_->set(this->getFromHistory());
     392                this->setCursorPosition( cursorPosition );
     393                return;
     394            }
     395        }
     396    }
     397
    359398    void Shell::scroll_up()
    360399    {
Note: See TracChangeset for help on using the changeset viewer.