예제 #1
0
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();
	}
}
예제 #2
0
파일: console.cpp 프로젝트: wesen/fatfs
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);
  }
}
예제 #3
0
static int
_inp_rl_tab_handler(int count, int key)
{
    if (rl_point != rl_end || !rl_line_buffer) {
        return 0;
    }

    ProfWin *current = wins_get_current();
    if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
        char *result = muc_autocomplete(current, rl_line_buffer);
        if (result) {
            rl_replace_line(result, 0);
            rl_point = rl_end;
            free(result);
        }
    } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
        ProfWin *window = wins_get_current();
        char *result = cmd_autocomplete(window, rl_line_buffer);
        if (result) {
            rl_replace_line(result, 0);
            rl_point = rl_end;
            free(result);
        }
    }

    return 0;
}
예제 #4
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);
	}
}
예제 #5
0
파일: minitalk.c 프로젝트: abenson/minitalk
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);
}
예제 #6
0
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);  
}
예제 #7
0
파일: test.c 프로젝트: prosbloom225/mmpc
 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);
 }
예제 #8
0
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 edit_deinit(const char *history_file,
		 int (*filter_cb)(void *ctx, const char *cmd))
{
	rl_set_prompt("");
	rl_replace_line("", 0);
	rl_redisplay();
	rl_callback_handler_remove();
	readline_free_completions();

	eloop_unregister_read_sock(STDIN_FILENO);

	if (history_file) {
		/* Save command history, excluding lines that may contain
		 * passwords. */
		HIST_ENTRY *h;
		history_set_pos(0);
		while ((h = current_history())) {
			char *p = h->line;
			while (*p == ' ' || *p == '\t')
				p++;
			if (filter_cb && filter_cb(edit_cb_ctx, p)) {
				h = remove_history(where_history());
				if (h) {
					free(h->line);
					free(h->data);
					free(h);
				} else
					next_history();
			} else
				next_history();
		}
		write_history(history_file);
	}
}
예제 #10
0
파일: minitalk.c 프로젝트: abenson/minitalk
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;
}
예제 #11
0
파일: daoMain.c 프로젝트: itsky71/dao
static void DaoSignalHandler( int sig )
{
#ifdef DAO_WITH_THREAD
	if( ! DThread_IsMain() ) return;
#endif

	DaoVmSpace_Stop( vmSpace, 1);
	if( count ++ ) exit(1);
	count += 1;

	if( readingline ){
		printf( "\n" );
#ifdef DAO_USE_READLINE
		if( rl_end ==0 ) printf( "type \"q\" to quit.\n" );
#ifndef MACOSX
		rl_replace_line( "", 0 );
		rl_forced_update_display();
#else
		rl_reset_terminal( "" );
#endif
#endif
	}else{
		printf( "keyboard interrupt...\n" );
	}
}
예제 #12
0
void cli_destroy(void)
{
	unsigned int i;

	if (!cli_event)
		return;

	if (cli_rl) {
		cli_rl = false;

		rl_replace_line("", 0);
		rl_crlf();
		rl_on_new_line();
		rl_redisplay();

		rl_message("");
		rl_callback_handler_remove();
	}

	sd_event_source_unref(cli_stdin);
	cli_stdin = NULL;

	for (i = 0; cli_sigs[i]; ++i) {
		sd_event_source_unref(cli_sigs[i]);
		cli_sigs[i] = NULL;
	}

	cli_cmds = NULL;
	sd_bus_detach_event(cli_bus);
	cli_bus = NULL;
	sd_event_unref(cli_event);
	cli_event = NULL;
}
예제 #13
0
파일: io.c 프로젝트: prosbloom225/mmpc
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;
}
예제 #14
0
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;
}
예제 #15
0
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
}
예제 #16
0
파일: occtl.c 프로젝트: fridex/ocserv
void handle_sigint(int signo)
{
#ifdef HAVE_ORIG_READLINE
	rl_reset_line_state();
	rl_replace_line("", 0);
	rl_crlf();
#endif
	rl_redisplay();
	return;
}
예제 #17
0
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;
}
예제 #18
0
void
ConsoleUI::processOutput() {
	FILE *stream = (rl_outstream == NULL) ? stdout : rl_outstream;
	int point, mark;
	char *buffer = NULL;
	char *prompt = NULL;

	// Save readline's state.
	point = rl_point;
	mark = rl_mark;
	if (rl_line_buffer != NULL) {
		buffer = strdup(rl_line_buffer);
	}
	if (rl_prompt != NULL) {
		prompt = strdup(rl_prompt);
	}
	rl_replace_line("", 0);
	rl_point = rl_mark = 0;
	rl_set_prompt("");
	rl_display_prompt = NULL;
	rl_redisplay();

	// If there was already a prompt (previous printed message didn't
	// contain a newline), then print it to the screen and clear the
	// prompt.
	if (prompt != NULL) {
		if (prompt[0] != '\0') {
			fputs(prompt, stream);
		}
		free(prompt);
		prompt = NULL;
	}
	// Make sure the prompt color will be set to default.
	prompt = strdup("\e[0m");

	while (!output.empty()) {
		char *msg = output.front();
		size_t len;

		len = strlen(msg);
		if (output.size() == 1 && len > 0 && msg[len - 1] != '\n') {
			// This is the last message and it doesn't end with a newline.
			// Use this message as prompt.
			char buf[1024 * 32];
			// Reset the prompt color.
			snprintf(buf, sizeof(buf) - 1, "%s\e[0m", msg);
			rl_set_prompt(buf);

			// Prevent prompt from being set to an empty string.
			if (prompt != NULL) {
				free(prompt);
				prompt = NULL;
			}
		} else {
예제 #19
0
static gboolean signal_handler(GIOChannel *channel, GIOCondition condition,
							gpointer user_data)
{
	static unsigned int __terminated = 0;
	struct signalfd_siginfo si;
	ssize_t result;
	int fd;

	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
		g_main_loop_quit(event_loop);
		return FALSE;
	}

	fd = g_io_channel_unix_get_fd(channel);

	result = read(fd, &si, sizeof(si));
	if (result != sizeof(si))
		return FALSE;

	switch (si.ssi_signo) {
	case SIGINT:
		rl_replace_line("", 0);
		rl_crlf();
		rl_on_new_line();
		rl_redisplay();
		break;
	case SIGTERM:
		if (__terminated == 0) {
			rl_replace_line("", 0);
			rl_crlf();
			g_main_loop_quit(event_loop);
		}

		__terminated = 1;
		break;
	}

	return TRUE;
}
예제 #20
0
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();
    }
}
예제 #21
0
파일: io.c 프로젝트: dpc/xmppconsole
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);
}
예제 #22
0
void ConsoleReader::run() {
    init();
#ifndef NOINPUT
    while (m->running) {
        const char *line = readline("");
        if (!line) {
           break;
        }
        rl_set_prompt("");
        rl_replace_line("", 0);
        m->server->dispatchConsoleCommand(line, m->server->getCommandSender());
    }
    exit(0);
#endif
}
예제 #23
0
파일: io.c 프로젝트: dpc/xmppconsole
static void handle_line_fake(char* line) {
    if (line != NULL) {
        if (prog_running) {
            rl_set_prompt(prompt);
            rl_already_prompted = 1;
        }
        return;
    }
    prog_running = 0;

    rl_set_prompt("");
    rl_replace_line("", 0);
    rl_redisplay();
    rl_set_prompt(prompt);
}
예제 #24
0
파일: minitalk.c 프로젝트: abenson/minitalk
static void handle_line_fake(char *line)
{
	/* We want to ignore when readline says it has the end of a message, as we'll
	   only care if the user presses ENTER.
	*/
	if (line != NULL) {
		rl_set_prompt(PROMPT);
		rl_already_prompted = 1;
	} else {
		rl_set_prompt("");
		rl_replace_line("", 0);
		rl_redisplay();
		rl_set_prompt(PROMPT);
	}
}
예제 #25
0
static void ctrl_c(int signal)
{
#ifdef USE_READLINE
	
	rl_replace_line("", '\0');
	rl_crlf();
	rl_forced_update_display();

#else

	LOG(stdout, "\n%s", PROMPT);
	fflush(stdout);

#endif
}
예제 #26
0
파일: misc.c 프로젝트: bminor/bash
/* Restore the _rl_saved_line_for_history if there is one. */
int
rl_maybe_unsave_line (void)
{
  if (_rl_saved_line_for_history)
    {
      /* Can't call with `1' because rl_undo_list might point to an undo
	 list from a history entry, as in rl_replace_from_history() below. */
      rl_replace_line (_rl_saved_line_for_history->line, 0);
      rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data;
      _rl_free_history_entry (_rl_saved_line_for_history);
      _rl_saved_line_for_history = (HIST_ENTRY *)NULL;
      rl_point = rl_end;	/* rl_replace_line sets rl_end */
    }
  else
    rl_ding ();
  return 0;
}
예제 #27
0
파일: misc.c 프로젝트: bminor/bash
void
rl_replace_from_history (HIST_ENTRY *entry, int flags)
{
  /* Can't call with `1' because rl_undo_list might point to an undo list
     from a history entry, just like we're setting up here. */
  rl_replace_line (entry->line, 0);
  rl_undo_list = (UNDO_LIST *)entry->data;
  rl_point = rl_end;
  rl_mark = 0;

#if defined (VI_MODE)
  if (rl_editing_mode == vi_mode)
    {
      rl_point = 0;
      rl_mark = rl_end;
    }
#endif
}
예제 #28
0
파일: misc.c 프로젝트: bminor/bash
/* Process and free undo lists attached to each history entry prior to the
   current entry, inclusive, reverting each line to its saved state.  This 
   is destructive, and state about the current line is lost.  This is not
   intended to be called while actively editing, and the current line is
   not assumed to have been added to the history list. */
void
_rl_revert_all_lines (void)
{
  int hpos;
  HIST_ENTRY *entry;
  UNDO_LIST *ul, *saved_undo_list;
  char *lbuf;

  lbuf = savestring (rl_line_buffer);
  saved_undo_list = rl_undo_list;
  hpos = where_history ();

  entry = (hpos == history_length) ? previous_history () : current_history ();
  while (entry)
    {
      if (ul = (UNDO_LIST *)entry->data)
	{
	  if (ul == saved_undo_list)
	    saved_undo_list = 0;
	  /* Set up rl_line_buffer and other variables from history entry */
	  rl_replace_from_history (entry, 0);	/* entry->line is now current */
	  entry->data = 0;			/* entry->data is now current undo list */
	  /* Undo all changes to this history entry */
	  while (rl_undo_list)
	    rl_do_undo ();
	  /* And copy the reverted line back to the history entry, preserving
	     the timestamp. */
	  FREE (entry->line);
	  entry->line = savestring (rl_line_buffer);
	}
      entry = previous_history ();
    }

  /* Restore history state */
  rl_undo_list = saved_undo_list;	/* may have been set to null */
  history_set_pos (hpos);
  
  /* reset the line buffer */
  rl_replace_line (lbuf, 0);
  _rl_set_the_line ();

  /* and clean up */
  xfree (lbuf);
}  
예제 #29
0
static int cli_signal_fn(sd_event_source *source,
			 const struct signalfd_siginfo *ssi,
			 void *data)
{
	if (ssi->ssi_signo == SIGCHLD) {
		cli_debug("caught SIGCHLD for %d", (int)ssi->ssi_pid);
	} else if (ssi->ssi_signo == SIGINT) {
		rl_replace_line("", 0);
		rl_crlf();
		rl_on_new_line();
		rl_redisplay();
	} else {
		cli_notice("caught signal %d, exiting..",
			   (int)ssi->ssi_signo);
		sd_event_exit(cli_event, 0);
	}

	return 0;
}
예제 #30
0
파일: test.c 프로젝트: prosbloom225/mmpc
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;
}