diff options
Diffstat (limited to 'Build/source/utils/asymptote/runhistory.in')
-rw-r--r-- | Build/source/utils/asymptote/runhistory.in | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/Build/source/utils/asymptote/runhistory.in b/Build/source/utils/asymptote/runhistory.in index ddf60e22f6d..78dcbb6d54f 100644 --- a/Build/source/utils/asymptote/runhistory.in +++ b/Build/source/utils/asymptote/runhistory.in @@ -22,6 +22,10 @@ using namespace run; typedef array stringarray; using types::stringArray; +namespace camp { +bool allowRender=true; +} + #if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES) #include <readline/readline.h> #include <readline/history.h> @@ -30,7 +34,7 @@ struct historyState { bool store; HISTORY_STATE state; }; - + typedef mem::map<CONST string, historyState> historyMap_t; historyMap_t historyMap; static HISTORY_STATE history_save; @@ -47,7 +51,7 @@ void store_history(HISTORY_STATE *dest) } } -stringarray* get_history(Int n) +stringarray* get_history(Int n) { int N=intcast(n); if(N <= 0) N=history_length; @@ -58,14 +62,15 @@ stringarray* get_history(Int n) HIST_ENTRY *last=history_get(offset+i); string s=last ? last->line : ""; (*a)[i]=s; - } + } return a; } -string historyfilename(const string &name) +string historyfilename(const string &name) { return historyname+"_"+name; } + #endif namespace run { @@ -81,7 +86,7 @@ void cleanup() #if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES) store_history(&history_save); int nlines=intcast(getSetting<Int>("historylines")); - for(historyMap_t::iterator h=historyMap.begin(); h != historyMap.end(); + for(historyMap_t::iterator h=historyMap.begin(); h != historyMap.end(); ++h) { history_set_history_state(&h->second.state); if(h->second.store) { @@ -94,7 +99,7 @@ void cleanup() #endif #ifdef HAVE_LIBGSL trans::GSLrngFree(); -#endif +#endif } } @@ -106,9 +111,9 @@ 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()); @@ -118,15 +123,15 @@ stringarray* history(string name, Int n=1) store_history(&history_save); HISTORY_STATE& history=historyMap[name].state; history_set_history_state(&history); - + if(newhistory) read_history(filename.c_str()); array *a=get_history(n); - + store_history(&history); history_set_history_state(&history_save); - + return a; #else unused(&n); @@ -154,7 +159,7 @@ string readline(string prompt=emptystring, string name=emptystring, return emptystring; #if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES) interact::init_readline(tabcompletion); - + store_history(&history_save); bool newhistory=historyMap.find(name) == historyMap.end(); historyState& h=historyMap[name]; @@ -163,7 +168,7 @@ string readline(string prompt=emptystring, string name=emptystring, if(newhistory) read_history(historyfilename(name).c_str()); - + static char *line=NULL; /* Return the memory to the free pool if the buffer has already been allocated. */ @@ -171,12 +176,14 @@ string readline(string prompt=emptystring, string name=emptystring, free(line); line=NULL; } - + /* Get a line from the user. */ + allowRender=false; line=readline(prompt.c_str()); - + allowRender=true; + if(!line) cout << endl; - + history_set_history_state(&history_save); return line ? string(line) : emptystring; @@ -203,7 +210,7 @@ void saveline(string name, string value, bool store=true) if(newhistory) read_history(historyfilename(name).c_str()); - + if(value != "") { add_history(value.c_str()); if(store) { @@ -211,10 +218,10 @@ void saveline(string name, string value, bool store=true) hout << value << endl; } } - + store_history(&history); history_set_history_state(&history_save); #else unused(&store); -#endif +#endif } |