Package: rxvt-unicode
Version: 9.07-1
Severity: wishlist
Tags: patch

>From time to time it happens that I paste some random content into the
terminal. It happens because of various reasons. Sometimes I select  something
in a GUI application and forget about it, sometimes I close  a window and the
clipboard points to something random.  Sometimes it ends up with me executing
something harmful.  I've created three patches. Every one on them uses a bit
different  method to cope with the problem. There are three because of a
discussion  I had with the author, but lost contact with him, so I file this
here.   I personally hope the "New handler solution" will be chosen.  So these
are the patches, every one gives an option to allow only one  line pastes.
Option set by a resource or by popup menu, filtering in the C++ code: rxvt-
unicode-9.07-pasteOneLine.cpp.filter.diff  Extension filtering every input in
the on_tt_write handler (overkill): rxvt-unicode-9.07-pasteOneLine.tt-
write.handler.diff  New handler usable in a Perl extension (extension
included): rxvt-unicode-9.07-pasteOneLine.paste.handler.diff


-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (600, 'testing'), (500, 'stable'), (50, 'unstable'), (1, 
'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.30-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -r -u rxvt-unicode-9.07/src/optinc.h rxvt-unicode-9.07-patched/src/optinc.h
--- rxvt-unicode-9.07/src/optinc.h	2010-01-14 22:33:14.000000000 +0100
+++ rxvt-unicode-9.07-patched/src/optinc.h	2010-04-08 02:36:08.000000000 +0200
@@ -62,4 +62,4 @@
 #else
  nodef(buffered)
 #endif
-
+ def(pasteOneLine,        35) // prevent myself from pasting "echo Harmless\n rm -rf /"
diff -r -u rxvt-unicode-9.07/src/rsinc.h rxvt-unicode-9.07-patched/src/rsinc.h
--- rxvt-unicode-9.07/src/rsinc.h	2010-01-14 22:33:14.000000000 +0100
+++ rxvt-unicode-9.07-patched/src/rsinc.h	2010-04-08 02:35:58.000000000 +0200
@@ -119,3 +119,4 @@
   def (blurradius)
   def (iconfile)
 #endif
+  def(pasteOneLine)
diff -r -u rxvt-unicode-9.07/src/screen.C rxvt-unicode-9.07-patched/src/screen.C
--- rxvt-unicode-9.07/src/screen.C	2010-04-08 02:52:29.000000000 +0200
+++ rxvt-unicode-9.07-patched/src/screen.C	2010-04-08 02:46:14.000000000 +0200
@@ -2673,15 +2673,19 @@
 void
 rxvt_term::paste (char *data, unsigned int len) NOTHROW
 {
+  const char *newline_pos;
+
   /* convert normal newline chars into common keyboard Return key sequence */
   for (unsigned int i = 0; i < len; i++)
     if (data[i] == C0_LF)
       data[i] = C0_CR;
 
+  newline_pos = option(Opt_pasteOneLine) ? (char*)memchr(data, C0_CR, len) : NULL;
+
   if (priv_modes & PrivMode_BracketPaste)
     tt_printf ("\e[200~");
 
-  tt_write (data, len);
+  tt_write (data, newline_pos ? newline_pos - data : len);
 
   if (priv_modes & PrivMode_BracketPaste)
     tt_printf ("\e[201~");
diff -r -u rxvt-unicode-9.07/src/xdefaults.C rxvt-unicode-9.07-patched/src/xdefaults.C
--- rxvt-unicode-9.07/src/xdefaults.C	2010-01-14 22:33:14.000000000 +0100
+++ rxvt-unicode-9.07-patched/src/xdefaults.C	2010-04-08 02:40:03.000000000 +0200
@@ -269,6 +269,7 @@
               STRG (Rs_iconfile, "iconFile", "icon", "file", "path to application icon image"),
 # endif
 #endif
+              BOOL (Rs_pasteOneLine, "pasteOneLine", NULL, Opt_pasteOneLine, 0, "paste only one line"),
               INFO ("e", "command arg ...", "command to execute")
             };
diff -r -u rxvt-unicode-9.07/src/hookinc.h rxvt-unicode-9.07-orig-patched//src/hookinc.h
--- rxvt-unicode-9.07/src/hookinc.h	2008-02-19 13:17:46.000000000 +0100
+++ rxvt-unicode-9.07-orig-patched//src/hookinc.h	2010-04-09 19:54:51.000000000 +0200
@@ -14,6 +14,8 @@
 
   def (SEL_CLICK)
 
+  def (PASTE)
+
   def (VIEW_CHANGE)
   def (SCROLL_BACK)
   def (LINE_UPDATE)
diff -r -u rxvt-unicode-9.07/src/screen.C rxvt-unicode-9.07-orig-patched//src/screen.C
--- rxvt-unicode-9.07/src/screen.C	2009-12-29 05:16:18.000000000 +0100
+++ rxvt-unicode-9.07-orig-patched//src/screen.C	2010-04-09 20:32:55.000000000 +0200
@@ -2681,7 +2681,7 @@
   if (priv_modes & PrivMode_BracketPaste)
     tt_printf ("\e[200~");
 
-  tt_write (data, len);
+  if (!HOOK_INVOKE ((this, HOOK_PASTE, DT_STR_LEN, data, len, DT_END))) tt_write (data, len);
 
   if (priv_modes & PrivMode_BracketPaste)
     tt_printf ("\e[201~");
diff -N -u -r rxvt-unicode-9.07/src/perl/paste-one-line_paste-handler rxvt-unicode-9.07-orig-patched/src/perl/paste-one-line_paste-handler
--- rxvt-unicode-9.07/src/perl/paste-one-line_paste-handler	1970-01-01 01:00:00.000000000 +0100
+++ rxvt-unicode-9.07-orig-patched/src/perl/paste-one-line_paste-handler	2010-04-11 23:49:32.000000000 +0200
@@ -0,0 +1,13 @@
+#! perl
+
+sub on_paste {
+  my ($self, $octets) = @_;
+
+  if( $octets =~ /^[^\r\n]+[\r\n]+/ ) {
+    $octets =~ s/[\r\n].*//g;
+    $self->tt_write( $octets );
+    return 1;
+  }
+
+  return 0;
+}
diff -N -u -r rxvt-unicode-9.07/src/perl/paste-one-line_tt-write-handler rxvt-unicode-9.07-orig-patched/src/perl/paste-one-line_tt-write-handler
--- rxvt-unicode-9.07/src/perl/paste-one-line_tt-write-handler	1970-01-01 01:00:00.000000000 +0100
+++ rxvt-unicode-9.07-orig-patched/src/perl/paste-one-line_tt-write-handler	2010-04-11 23:49:31.000000000 +0200
@@ -0,0 +1,13 @@
+#! perl
+
+sub on_tt_write {
+  my ($self, $octets) = @_;
+
+  if( $octets =~ /^[^\r\n]+[\r\n]+/ ) {
+    $octets =~ s/[\r\n].*//g;
+    $self->tt_write($octets);
+    return 1;
+  }
+
+  return 0;
+}

Reply via email to