Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

[PATCH] Add signal for paste detection events #531

Open
irssibot opened this issue Sep 17, 2007 · 2 comments
Open

[PATCH] Add signal for paste detection events #531

irssibot opened this issue Sep 17, 2007 · 2 comments

Comments

@irssibot
Copy link
Collaborator

The attached patch adds two signals, "gui paste detected" and "gui paste flush" that allows a script to intercept certain paste events. It doesn't intercept the normal paste key (^K) but adds two more keys that scripts can use (^O and ^P).

It currently hardcodes the keys that are allowed, I don't like that much but I can't think of a nice way to make it configurable. (I guess a perl function to register interest, but that seems like a huge amount of effort for something so simple.)

I've written a script to use this, you can find it at http://dgl.cx/irssi/pastie.pl

It would be nice to see this in Irssi core, as I think the script could be quite useful.

@irssibot
Copy link
Collaborator Author

      • Attachment 146 by @dgl

irssi-paste-signal.patch

Index: src/fe-text/gui-readline.c
===================================================================
--- src/fe-text/gui-readline.c	(revision 4605)
+++ src/fe-text/gui-readline.c	(working copy)
@@ -317,13 +317,44 @@
 	g_string_free(str, TRUE);
 }
 
+static void paste_flush_signal() {
+        unsigned int i;
+	unichar *arr;
+        char out[10];
+        char *text = gui_entry_get_text(active_entry);
+        GString *str = g_string_new(text);
+
+        g_free(text);
+
+	arr = (unichar *) paste_buffer->data;
+
+        for (i = 0; i < paste_buffer->len; i++) {
+                if (active_entry->utf8) {
+                        out[utf16_char_to_utf8(arr[i], out)] = '\0';
+                        g_string_append(str, out);
+                } else if (term_type == TERM_TYPE_BIG5) {
+                        if (arr[i] > 0xff)
+                                g_string_append_c(str, (arr[i] >> 8) & 0xff);
+                        g_string_append_c(str, arr[i] & 0xff);
+                } else {
+                        g_string_append_c(str, arr[i]);
+                }
+        }
+        signal_emit("gui paste flush", 1, str->str);
+
+        g_string_free(str, TRUE);
+}
+
 static void paste_flush(int send)
 {
 	gui_entry_set_text(active_entry, paste_entry);
 	gui_entry_set_pos(active_entry, paste_entry_pos);
 
-	if (send)
+	if (send == TRUE)
 		paste_send();
+        else if (send)
+                paste_flush_signal();
+
 	g_array_set_size(paste_buffer, 0);
 
 	gui_entry_set_prompt(active_entry,
@@ -376,6 +407,8 @@
 		gui_entry_set_prompt(active_entry, str);
 		gui_entry_set_text(active_entry, "");
 		g_free(str);
+
+                signal_emit("gui paste detected", 1, paste_line_count);
 	}
 	return TRUE;
 }
@@ -411,8 +444,9 @@
 	}
 
 	/* continuing quick hits */
-	if ((key == 11 || key == 3) && paste_prompt) {
-		paste_flush(key == 11);
+	if ((key == 11 || key == 3 || key == 15 || key == 16) && paste_prompt) {
+                /* 15 (^O) and 16 (^P) can be used by a script */
+		paste_flush(key == 11 ? TRUE : key == 3 ? FALSE : key);
 		return TRUE;
 	}
 
Index: docs/signals.txt
===================================================================
--- docs/signals.txt	(revision 4605)
+++ docs/signals.txt	(working copy)
@@ -319,6 +319,8 @@
 
 gui-readline.c:
  "gui key pressed", int key
+ "gui paste detected", int lines
+ "gui paste flush", int key, char *paste_buffer
 
 gui-printtext.c:
  "beep"

@irssibot
Copy link
Collaborator Author

      • Comment 1088 by @ms

    +1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant