// Store a deep copy of the current readline history in dest.
void store_history(HISTORY_STATE *dest)
{
HISTORY_STATE *src=history_get_history_state();
if(src) {
*dest=*src;
for(Int i=0; i < src->length; ++i)
dest->entries[i]=src->entries[i];
free(src);
}
}
// Return the last n lines of the history named name.
stringarray* history(string name, Int n=1)
{
#if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES)
bool newhistory=historyMap.find(name) == historyMap.end();
string filename;
if(newhistory) {
filename=historyfilename(name);
std::ifstream exists(filename.c_str());
if(!exists) return new array(0);
}
return a;
#else
unused(&n);
return new array(0);
#endif
}
// Return the last n lines of the interactive history.
stringarray* history(Int n=0)
{
#if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES)
return get_history(n);
#else
unused(&n);
return new array(0);
#endif
}
// Prompt for a string using prompt, the GNU readline library, and a
// local history named name.
string readline(string prompt=emptystring, string name=emptystring,
bool tabcompletion=false)
{
bool stdinIsTty=isatty(STDIN_FILENO);
bool hasInpipe=getSetting<Int>("inpipe") >= 0;
if(!(stdinIsTty || hasInpipe))
{
return emptystring;
}
#if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES)
interact::init_readline(tabcompletion);
// Save a string in a local history named name.
// If store=true, store the local history in the file historyfilename(name).
void saveline(string name, string value, bool store=true)
{
#if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES)
store_history(&history_save);
bool newhistory=historyMap.find(name) == historyMap.end();
historyState& h=historyMap[name];
h.store=store;
HISTORY_STATE& history=h.state;
history_set_history_state(&history);