Exemple #1
0
const char *command_history_next(WINDOW_REC *window, const char *text)
{
	GList *pos, **phistpos;

	phistpos = window_history ? &window->histpos : &histpos;

	pos = *phistpos;

	if (pos != NULL)
		*phistpos = (*phistpos)->next;

	if (*text != '\0' &&
	    (pos == NULL || strcmp(pos->data, text) != 0)) {
		/* save the old entry to history */
		command_history_add(window, text);
	}
	return *phistpos == NULL ? "" : (*phistpos)->data;
}
Exemple #2
0
const char *command_history_prev(WINDOW_REC *window, const char *text)
{
	GList *pos, **phistpos;

	phistpos = window_history ? &window->histpos : &histpos;

	pos = *phistpos;
	if (*phistpos == NULL)
		*phistpos = g_list_last(window_history ? window->cmdhist : cmdhist);
	else
		*phistpos = (*phistpos)->prev;

	if (*text != '\0' &&
	    (pos == NULL || strcmp(pos->data, text) != 0)) {
		/* save the old entry to history */
		command_history_add(window, text);
	}

	return *phistpos == NULL ? "" : (*phistpos)->data;
}
  /* Called when user hits "Enter" key in command entry.  The action to take
     |  depends on where the combo box is.  If it's in the command window, we can
     |  immediately execute the command and carry on.  If it's in the status
     |  line hbox, then we need stop the command entry g_main_loop from running
     |  and save the allocated string so it can be returned from
     |  ghid_command_entry_get()
   */
static void
command_entry_activate_cb (GtkWidget * widget, gpointer data)
{
  gchar *command;

  command =
    g_strdup (ghid_entry_get_text (GTK_WIDGET (ghidgui->command_entry)));
  gtk_entry_set_text (ghidgui->command_entry, "");

  if (*command)
    command_history_add (command);

  if (ghidgui->use_command_window)
    {
      hid_parse_command (command);
      g_free (command);
    }
  else
    {
      if (loop && g_main_loop_is_running (loop))	/* should always be */
	g_main_loop_quit (loop);
      command_entered = command;	/* Caller will free it */
    }
}
Exemple #4
0
void handle_key(int key)
{
        const char *keyname;
	char *str;
        int add_history;

	/* Quit if we get 5 CTRL-C's in a row. */
	if (key != CTRL('c'))
		sigint_count = 0;
	else if (++sigint_count >= 5)
		raise(SIGTERM);

	idle_time = time(NULL);

	if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
		handle_key_redirect(key);
		return;
	}

	switch (key)
	{
	case 27:
		key = getch();
		if (key == 'O') {
			key = getch();
			switch (key) {
			case 'a':
                                str = g_strdup("CTRL-Up");
				break;
			case 'b':
                                str = g_strdup("CTRL-Down");
				break;
			case 'c':
                                str = g_strdup("CTRL-Right");
                                break;
			case 'd':
                                str = g_strdup("CTRL-Left");
				break;
			default:
				return;
			}
		} else if (key == toupper(key) && key != tolower(key))
			str = g_strdup_printf("ALT-SHIFT-%c", key);
		else {
			keyname = get_key_name(key);
			if (keyname != NULL)
				str = g_strdup_printf("ALT-%s", keyname);
			else if (key >= 32 && key < 256 && key != 128)
				str = g_strdup_printf("ALT-%c", toupper(key));
			else {
				str = g_strdup_printf("ALT-%d", key);
			}
		}
		key_pressed(str, NULL);
		g_free(str);
		break;
	case '\n':
	case 13:
		key_pressed("Return", NULL);

		str = gui_entry_get_text();
		if (*str == '\0') break;

		translate_output(str);

                add_history = TRUE;
		if (redir == NULL) {
			signal_emit("send command", 3, str,
				    active_win->active_server,
				    active_win->active);
		} else {
			if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
                                add_history = FALSE;
			handle_entry_redirect(str);
		}

		if (add_history) {
			command_history_add(active_win, gui_entry_get_text(),
					    FALSE);
		}
		gui_entry_set_text("");
		command_history_clear_pos(active_win);
		break;

	default:
                keyname = get_key_name(key);
		if (keyname != NULL) {
			key_pressed(keyname, NULL);
			break;
		}
		if (key >= 0 && key < 32) {
			str = g_strdup_printf("CTRL-%c",
					      key == 0 ? ' ' :
					      (key == 31 ? '-' : key+'A'-1));
			key_pressed(str, NULL);
			g_free(str);
			break;
		}

		if (key < 256) {
			char str[2];

			str[0] = toupper(key); str[1] = '\0';
			key_pressed(str, NULL);
			gui_entry_insert_char((char) key);
		}
		break;
	}
}