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(); } }
void _rl_arg_init () { rl_save_prompt (); _rl_argcxt = 0; RL_SETSTATE(RL_STATE_NUMERICARG); }
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); } }
void * hide_password(void) { rl_save_prompt(); if (rl_point > 0) rl_show_char('*'); rl_restore_prompt(); }
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 __fmtstring(1, 0) cli_display(const char *fmt, va_list ap) { int point, end; char *buf; point = rl_point; end = rl_end; rl_point = rl_end = 0; rl_save_prompt(); rl_clear_message(); if (vasprintf(&buf, fmt, ap) < 0) fprintf(rl_outstream, "cli_display: out of memory\n"); else { fprintf(rl_outstream, "%s\n", buf); xfree(buf); } rl_restore_prompt(); rl_point = point; rl_end = end; rl_forced_update_display(); }
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 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); }
/* display (or remove, if message == NULL) message in echo area, with the appropriate bookkeeping */ void message_in_echo_area(char *message) { static int message_in_echo_area = FALSE; DPRINTF1(DEBUG_READLINE, "message: %s", mangle_string_for_debug_log(message, MANGLE_LENGTH)); if (message) { rl_save_prompt(); message_in_echo_area = TRUE; rl_message(message); } else { if (message_in_echo_area) rl_restore_prompt(); rl_clear_message(); message_in_echo_area = FALSE; } }
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; }
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; }
static char *cli_append_multiline(char *line) { bool complete = false; size_t len; char *s; if (line == NULL && multiline == NULL) { eof = true; return NULL; } len = strlen(line); if (line[len - 1] == '\\') { line[len - 1] = '\0'; len--; } else if (multiline == NULL) return line; else complete = 1; if (multiline == NULL) { multiline = line; rl_save_prompt(); rl_clear_message(); rl_set_prompt(".... "); } else { len += strlen(multiline); s = xmalloc(len + 1); snprintf(s, len + 1, "%s%s", multiline, line); xfree(multiline); multiline = s; } line = NULL; if (complete) { line = multiline; multiline = NULL; rl_restore_prompt(); } return 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(); } }