Merged from silc_1_0_branch (second merge).
[crypto.git] / apps / irssi / src / fe-text / gui-readline.c
index 1cabfac72b634e77e804139e1619e97cc7b97600..4de1936e3adc52b853ab2dbb6498172eea1a42cb 100644 (file)
@@ -81,10 +81,10 @@ static void handle_key_redirect(int key)
        data = redir->data;
        g_free_and_null(redir);
 
+       gui_entry_set_prompt(active_entry, "");
+
        if (func != NULL)
                func(key, data, active_win->active_server, active_win->active);
-
-       gui_entry_set_prompt(active_entry, "");
 }
 
 static void handle_entry_redirect(const char *line)
@@ -98,12 +98,12 @@ static void handle_entry_redirect(const char *line)
        data = redir->data;
        g_free_and_null(redir);
 
+       gui_entry_set_prompt(active_entry, "");
+
        if (func != NULL) {
                func(line, data, active_win->active_server,
                     active_win->active);
        }
-
-       gui_entry_set_prompt(active_entry, "");
 }
 
 static int get_scroll_count(void)
@@ -134,17 +134,20 @@ static void window_next_page(void)
        gui_window_scroll(active_win, get_scroll_count());
 }
 
-void handle_key(unichar key)
+static void sig_gui_key_pressed(gpointer keyp)
 {
+        unichar key;
        char str[20];
 
-       idle_time = time(NULL);
+       key = GPOINTER_TO_INT(keyp);
 
        if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
                handle_key_redirect(key);
                return;
        }
 
+       idle_time = time(NULL);
+
        if (key < 32) {
                /* control key */
                 str[0] = '^';
@@ -179,6 +182,7 @@ static void key_send_line(void)
 {
        HISTORY_REC *history;
         char *str, *add_history;
+       gint flags = (redir ? redir->flags : 0);
 
        str = gui_entry_get_text(active_entry);
 
@@ -194,9 +198,13 @@ static void key_send_line(void)
                            active_win->active_server,
                            active_win->active);
        } else {
-               if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
+               if (flags & ENTRY_REDIRECT_FLAG_HIDDEN && add_history) {
+                       memset(add_history, 0, strlen(add_history));
                         g_free_and_null(add_history);
+               }
                handle_entry_redirect(str);
+               if (flags & ENTRY_REDIRECT_FLAG_HIDDEN && str)
+                       memset(str, 0, strlen(str));
        }
 
        if (add_history != NULL) {
@@ -367,8 +375,10 @@ static void sig_input(void)
                if (!term_detached)
                        signal_emit("command quit", 1, "Lost terminal");
        } else {
-               for (i = 0; i < ret; i++)
-                       handle_key(buffer[i]);
+               for (i = 0; i < ret; i++) {
+                       signal_emit("gui key pressed", 1,
+                                   GINT_TO_POINTER(buffer[i]));
+               }
        }
 }
 
@@ -762,6 +772,7 @@ void gui_readline_init(void)
 
        signal_add("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
        signal_add("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
+       signal_add("gui key pressed", (SIGNAL_FUNC) sig_gui_key_pressed);
 }
 
 void gui_readline_deinit(void)
@@ -825,4 +836,5 @@ void gui_readline_deinit(void)
 
        signal_remove("window changed automatic", (SIGNAL_FUNC) sig_window_auto_changed);
        signal_remove("gui entry redirect", (SIGNAL_FUNC) sig_gui_entry_redirect);
+       signal_remove("gui key pressed", (SIGNAL_FUNC) sig_gui_key_pressed);
 }