Changeset 14984 for trunk


Ignore:
Timestamp:
03/04/13 20:14:24 (12 years ago)
Author:
tbretz
Message:
Update the prompt in regular intervals even if GetUpdatePrompt returns nothing; added ::Static* functions which allow to run a simplified version of readline
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r14557 r14984  
    317317    }
    318318
    319     const string p = GetUpdatePrompt();
     319    string p = GetUpdatePrompt();
    320320    if (p.empty())
    321         return;
     321        p = rl_prompt;
    322322
    323323    UpdatePrompt("");
     
    12621262// --------------------------------------------------------------------------
    12631263//
     1264//! Writes the current history to the file defined by fName and
     1265//! replaces the history by the data from the given file.
     1266//!
     1267//! @param fname
     1268//!    Name of the history file to read
     1269//!
     1270void Readline::StaticPushHistory(const string &fname="")
     1271{
     1272    write_history(This->fName.c_str());
     1273    stifle_history(0);
     1274    unstifle_history();
     1275    read_history(fname.c_str());
     1276}
     1277
     1278// --------------------------------------------------------------------------
     1279//
     1280//! Writes the current history to the file with the given name
     1281//! and replaces the history by the file defined by fName.
     1282//!
     1283//! @param fname
     1284//!    Name of the history file to write (it will be truncated to 1000 lines)
     1285//!
     1286void Readline::StaticPopHistory(const string &fname="")
     1287{
     1288    write_history(fname.c_str());
     1289    history_truncate_file(fname.c_str(), 1000);
     1290    stifle_history(0);
     1291    unstifle_history();
     1292    read_history(This->fName.c_str());
     1293}
     1294
     1295// --------------------------------------------------------------------------
     1296//
     1297//! Just calls readline and thus allows to just prompt for something.
     1298//! Adds everything to the history except '.q'
     1299//!
     1300//! @param prompt
     1301//!    Prompt to be displayed
     1302//!
     1303//! @return
     1304//!    String entered by the user ('.q' is Ctrl-d is pressed)
     1305//!
     1306string Readline::StaticPrompt(const string &prompt)
     1307{
     1308    char *buf = readline(prompt.c_str());
     1309    if (!buf)
     1310        return ".q";
     1311
     1312    const string str(buf);
     1313    if (Tools::Trim(str)!=".q")
     1314        add_history(buf);
     1315    free(buf);
     1316
     1317    return str;
     1318}
     1319
     1320// --------------------------------------------------------------------------
     1321//
    12641322//! Process a single line. All lines are added to the history, but only
    12651323//! accepted lines are written to the command log. In this case fLine is
  • trunk/FACT++/src/Readline.h

    r14069 r14984  
    143143
    144144    static Readline *Instance() { return This; }
     145
     146    static void        StaticPushHistory(const std::string &fname);
     147    static std::string StaticPrompt(const std::string &prompt);
     148    static void        StaticPopHistory(const std::string &fname);
    145149};
    146150
Note: See TracChangeset for help on using the changeset viewer.