Changeset 10275 for trunk


Ignore:
Timestamp:
03/30/11 16:00:15 (14 years ago)
Author:
tbretz
Message:
Implemented that all identical previous history entries are removed from the history by default.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Readline.cc

    r10183 r10275  
    470470//
    471471//! Adds the given string to the history buffer of readline's history by
    472 //! calling add_history. If skip is set to true str will be compared
    473 //! with the last line added to the history and only be added if it difers.
     472//! calling add_history.
    474473//!
    475474//! @param str
     
    478477//!
    479478//! @param skip
    480 //!    If skip is true do not add a new entry if it is identical to
    481 //!    the last one.
    482 //
    483 void Readline::AddToHistory(const string &str, bool skip)
    484 {
    485     if (skip && fLastLine==str)
     479//!    If skip is 1 and str matches the last added entry in the history,
     480//!    the entry is skipped. If skip==2, all entries matching str are
     481//!    removed from the history before the new entry is added as last one.
     482//!    <skip==2 is the default>
     483//
     484void Readline::AddToHistory(const string &str, int skip)
     485{
     486    if (skip==1 && fLastLine==str)
    486487        return;
    487488
     
    489490        return;
    490491
     492    while (skip==2)
     493    {
     494        int p = history_search_pos(str.c_str(), 0, 0);
     495        if (p<0)
     496            break;
     497
     498        delete remove_history(p);
     499    }
     500
    491501    add_history(str.c_str());
    492502    fLastLine = str;
    493503}
    494504
     505// --------------------------------------------------------------------------
     506//
     507//! @returns
     508//!     a string containing [{fLine}]
     509//
    495510string Readline::GetLinePrompt() const
    496511{
  • trunk/FACT++/src/Readline.h

    r10183 r10275  
    7171    std::string GetName() const { return fName; }
    7272
    73     void AddToHistory(const std::string &str, bool skip=true);
     73    void AddToHistory(const std::string &str, int skip=2);
    7474    static bool ClearHistory();
    7575    std::vector<const char*> GetHistory() const;
Note: See TracChangeset for help on using the changeset viewer.