void cli_printv(const char *fmt, va_list args) { SHL_PROTECT_ERRNO; _shl_free_ char *line = NULL; int point; bool async; /* In case we print messages during readline() activity, we need to * correctly save and restore RL-internal state. */ async = is_cli() && !RL_ISSTATE(RL_STATE_DONE); if (async) { point = rl_point; line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); } vprintf(fmt, args); if (async) { rl_restore_prompt(); rl_replace_line(line, 0); rl_point = point; rl_redisplay(); } }
int io_handle_enter(int x, int y) { char* line = NULL; line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 1); rl_redisplay(); //cmd_execute(line); if (strcmp(line, "") != 0) { add_history(line); } free(line); /* rl_set_prompt(prompt); */ /* rl_redisplay(); */ // wip - clear line on enter wmove(winCommandMode, 1, 1); //wprintw(winCommandMode, " "); wclrtoeol(winCommandMode); wmove(winCommandMode, 1, 1); wprintw(winCommandMode, ">"); wrefresh(winCommandMode); /* force readline to think that the current line was "eaten" and executed */ rl_done = 1; return 0; }
void rl_printf(const char *fmt, ...) { va_list args; bool save_input; char *saved_line; int saved_point; save_input = !RL_ISSTATE(RL_STATE_DONE); if (save_input) { saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); } va_start(args, fmt); vprintf(fmt, args); va_end(args); if (save_input) { rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_forced_update_display(); free(saved_line); } }
static void print_line(char *line) { char *saved_line = NULL; int saved_point = 0; /* This is readline stuff. - save the cursor position - save the current line contents - set the line to blank - tell readline we're done mucking - print the message - restore the standard prompt - restore the line contents - restore the cursor position - tell readline we're done mucking (again) */ saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("",0); rl_redisplay(); fprintf(stdout, "%s", line); rl_set_prompt(PROMPT); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); }
static int handle_enter(int x, int y) { char *line = NULL; /* Handle when a user presses enter. - Save the contents of the line. - Set the prompt to nothing. - Blank the line. - pass the message to the message handler - rl_copy_text returns malloc'd mem, so free it - restore the prompt - tell readline we're done mucking */ line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 1); rl_redisplay(); handle_msg(line); free(line); rl_set_prompt(PROMPT); rl_redisplay(); rl_done = 1; return 0; }
void Console::writeAsync(QString string) { int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0; char *saved_line = NULL; int saved_point = 0; if (need_hack) { saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); } std::cout << "\r" << string.toStdString(); if (need_hack) { rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); } }
void PrintAndLog(char *fmt, ...) { char *saved_line; int saved_point; va_list argptr, argptr2; static FILE *logfile = NULL; static int logging=1; // lock this section to avoid interlacing prints from different threats pthread_mutex_lock(&print_lock); if (logging && !logfile) { logfile=fopen(logfilename, "a"); if (!logfile) { fprintf(stderr, "Can't open logfile, logging disabled!\n"); logging=0; } } int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0; if (need_hack) { saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); } va_start(argptr, fmt); va_copy(argptr2, argptr); vprintf(fmt, argptr); printf(" "); // cleaning prompt va_end(argptr); printf("\n"); if (need_hack) { rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); } if (logging && logfile) { vfprintf(logfile, fmt, argptr2); fprintf(logfile,"\n"); fflush(logfile); } va_end(argptr2); if (flushAfterWrite == 1) //buzzy { fflush(NULL); } //release lock pthread_mutex_unlock(&print_lock); }
void printlog(int c) { char* saved_line; int saved_point; saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 0); rl_redisplay(); //printf("Message: %d\n", c); rl_set_prompt(prompt); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); }
void PrintAndLog(char *fmt, ...) { char *saved_line; int saved_point; va_list argptr, argptr2; static FILE *logfile = NULL; static int logging=1; if (logging && !logfile) { logfile=fopen(logfilename, "a"); if (!logfile) { fprintf(stderr, "Can't open logfile, logging disabled!\n"); logging=0; } } int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0; if (need_hack) { saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); } va_start(argptr, fmt); va_copy(argptr2, argptr); vprintf(fmt, argptr); printf(" "); // cleaning prompt va_end(argptr); printf("\n"); if (need_hack) { rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); } if (logging && logfile) { vfprintf(logfile, fmt, argptr2); fprintf(logfile,"\n"); fflush(logfile); } va_end(argptr2); }
void rl_redisplay_mod() { /* char *line = NULL; */ /* // grab last char and redisplay */ /* line = rl_copy_text(rl_end, rl_end-1); */ /* wprintw(winCommandMode, line); */ /* wrefresh(winCommandMode); */ /* rl_redisplay(); */ /* refresh(); */ char *line = NULL; line = rl_copy_text(0, rl_end); wmove(winCommandMode, 1, 2); wclrtoeol(winCommandMode); wprintw(winCommandMode, line); wrefresh(winCommandMode); rl_redisplay(); refresh(); }
std::streamsize Console::ReadlineStreambuf::xsputn(const char* s, std::streamsize count) { int saved_point = rl_point; char *saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); outStream.sputn(s, count); rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); return count; }
void ConsoleReader::println(const string &s) { #ifndef NOINPUT m->lock.lock(); int savedPoint = rl_point; char *savedLine = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 0); rl_redisplay(); m->cout << s << '\n'; rl_set_prompt(">"); rl_replace_line(savedLine, 0); rl_point = savedPoint; rl_redisplay(); m->lock.unLock(); #else puts(s.c_str()); #endif }
int Console::ReadlineStreambuf::overflow(int c) { int saved_point = rl_point; char *saved_line = rl_copy_text(0, rl_end); rl_save_prompt(); rl_replace_line("", 0); rl_redisplay(); char ch = c; outStream.sputn(&ch, 1); rl_restore_prompt(); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); free(saved_line); return 1; }
int io_handle_enter(int x, int y) { char* line = NULL; line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 0); rl_redisplay(); //cmd_execute(line); if (strcmp(line, "") != 0) { add_history(line); } free(line); //rl_set_prompt(prompt); rl_redisplay(); /* force readline to think that the current line was "eaten" and executed */ rl_done = 1; return 0; }
static void io_async_print(print_func func, void* data) { char* saved_line; int saved_point; saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_set_prompt(""); rl_replace_line("", 0); rl_redisplay(); (*func)(data); if (prog_running) { rl_set_prompt(prompt); rl_replace_line(saved_line, 0); rl_point = saved_point; rl_redisplay(); } else { /* FIXME: This leaves prompt on /quit. Fix it. */ rl_redisplay(); } free(saved_line); }
void rl_fprintf(FILE *f, char *fmt, ...) { int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0; char *saved_line = NULL; int saved_point = 0; va_list args; if (need_hack) { rl_save_prompt(); if (rl_end > 0) { saved_point = rl_point; saved_line = rl_copy_text(0, rl_end); rl_replace_line("", 0); } rl_redisplay(); } va_start(args, fmt); vfprintf(f, fmt, args); va_end(args); if (need_hack) { rl_restore_prompt(); if (saved_line != NULL) { rl_replace_line(saved_line, 0); rl_point = saved_point; free(saved_line); } rl_redisplay(); } }
static int complete(lua_State *L) { const char* line; char* out = NULL; line = lua_tostring(L, 1); rl_insert_text(line); lua_pop(L, 1); rl_complete(0, 0); if(rl_outstream == NULL) return 0; if (!lua_istable(L, -1)) { out = rl_copy_text(0, rl_end); /* Nothing found */ if (out[0] == '\0') lua_pushfstring(L, line); else lua_pushfstring(L, out); free(out); } rl_delete_text(0, rl_end); rl_point = 0; return 1; }
char * octave_rl_copy_line (void) { return rl_copy_text (0, rl_end); }