From: Philipp Stephani <p.stephani2@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Olaf Rogalsky <olaf.rogalsky@t-online.de>,
Emacs developers <emacs-devel@gnu.org>,
Yuri Khan <yuri.v.khan@gmail.com>
Subject: Re: X selection access in xterm (OSC 52)
Date: Thu, 09 Apr 2015 20:07:18 +0000 [thread overview]
Message-ID: <CAArVCkRuhbo93iU0QvT0JB7bMb6c9PoPLxrf4Rg1x4tL_sERvQ@mail.gmail.com> (raw)
In-Reply-To: <CAArVCkTtTPBRZicD-OvKzM=2AfRSFbNkXr1KGSXcxq763CrZbA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 737 bytes --]
Philipp Stephani <p.stephani2@gmail.com> schrieb am Do., 9. Apr. 2015 um
20:47 Uhr:
> I took a second look at HTerm, and found that its FAQ (
> http://git.chromium.org/gitweb/?p=chromiumos/platform/assets.git;a=blob;f=chromeapps/nassh/doc/faq.txt)
> states:
>
> "Clipboard read is not implemented. Reading is a security hole you
> probably didn't want anyway."
>
> Since I can't test the get-selection function and it's considered a
> security hole, I'm afraid I can't implement it.
> This only affects get-selection, not set-selection.
>
FWIW, here's my WIP patch for gui-get-selection, in case anybody wants to
implement this. It differs from Olaf's code mainly in using a temp buffer
and the existing xterm--query helper function.
[-- Attachment #1.2: Type: text/html, Size: 1468 bytes --]
[-- Attachment #2: 0001-Implement-OSC-52-functionality-for-getting-the-X-sel.patch --]
[-- Type: application/octet-stream, Size: 4560 bytes --]
From f0af6dea559e000c90873f30c294ae6ce9a5922a Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Thu, 9 Apr 2015 22:05:19 +0200
Subject: [PATCH] Implement OSC-52 functionality for getting the X selection
---
lisp/term/xterm.el | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index f4d1a84..695091f 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -38,7 +38,8 @@ If a list, assume that the listed features are supported, without checking.
The relevant features are:
modifyOtherKeys -- if supported, more key bindings work (e.g., \"\\C-,\")
reportBackground -- if supported, Xterm reports its background color
- setSelection -- if supported, Xterm saves yanked text to the X selection"
+ getSelection -- if supported, Xterm yanks text from the X selection
+ setSelection -- if supported, Xterm saves killed text to the X selection"
:version "24.1"
:group 'xterm
:type '(choice (const :tag "No" nil)
@@ -47,6 +48,7 @@ The relevant features are:
;; `terminal-init-xterm' as well.
(set (const :tag "modifyOtherKeys support" modifyOtherKeys)
(const :tag "report background" reportBackground)
+ (const :tag "get X selection" getSelection)
(const :tag "set X selection" setSelection))))
(defcustom xterm-max-cut-length 100000
@@ -644,6 +646,7 @@ string bytes that can be copied is 3/4 of this value."
;; as well. gnome-terminal doesn't and is excluded by this
;; test.
(when (>= version 203)
+ (terminal-init-xterm-activate-get-selection)
(terminal-init-xterm-activate-set-selection))))))
(defun xterm--query (query handlers)
@@ -725,6 +728,8 @@ We run the first FUNCTION whose STRING matches the input events."
(when (memq 'modifyOtherKeys xterm-extra-capabilities)
(terminal-init-xterm-modify-other-keys))
+ (when (memq 'getSelection xterm-extra-capabilities)
+ (terminal-init-xterm-activate-get-selection))
(when (memq 'setSelection xterm-extra-capabilities)
(terminal-init-xterm-activate-set-selection)))
@@ -746,6 +751,13 @@ We run the first FUNCTION whose STRING matches the input events."
(push "\e[?2004l" (terminal-parameter nil 'tty-mode-reset-strings))
(push "\e[?2004h" (terminal-parameter nil 'tty-mode-set-strings)))
+(defun terminal-init-xterm-activate-get-selection ()
+ "Terminal initialization for `gui-get-selection'."
+ ;; All text terminals are represented by the nil GUI type. We need
+ ;; to detect XTerm again in `xterm--get-selection' using the
+ ;; terminal parameters.
+ (gui-method-define gui-get-selection nil #'xterm--get-selection))
+
(defun terminal-init-xterm-activate-set-selection ()
"Terminal initialization for `gui-set-selection'."
;; All text terminals are represented by the nil GUI type. We need
@@ -753,6 +765,33 @@ We run the first FUNCTION whose STRING matches the input events."
;; terminal parameters.
(gui-method-define gui-set-selection nil #'xterm--set-selection))
+(defun xterm--get-selection (type data-type)
+ (unless (eq data-type 'STRING)
+ (error "Unsupported data type %S" data-type))
+ (let* ((init-function (terminal-parameter nil 'terminal-initted))
+ (xterm (eq init-function 'terminal-init-xterm))
+ (screen (eq init-function 'terminal-init-screen)))
+ ;; Only do something if the current terminal is actually an XTerm
+ ;; or screen.
+ (when (or xterm screen)
+ (let ((query (concat
+ "\e]52;"
+ (cond
+ ((eq type 'PRIMARY) "p")
+ ((eq type 'CLIPBOARD) "c")
+ (t (error "Invalid type %S" type)))
+ ";")))
+ (with-temp-buffer
+ (xterm--query
+ (concat (when screen "\eP") query "?\a" (when screen "\e\\"))
+ (list (cons query (lambda ()
+ (while (let ((char (read-char)))
+ (unless (eq char ?\a)
+ (insert char)
+ t)))))))
+ (base64-decode-region (point-min) (point-max))
+ (buffer-substring-no-properties (point-min) (point-max)))))))
+
(defun xterm--set-selection (type data)
"Copy DATA to the X selection using the OSC 52 escape sequence.
--
2.3.5
next prev parent reply other threads:[~2015-04-09 20:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-08 18:18 X selection access in xterm (OSC 52) Philipp Stephani
2015-02-08 18:43 ` Eli Zaretskii
2015-02-08 18:48 ` Philipp Stephani
2015-02-08 19:00 ` Stefan Monnier
2015-02-09 3:04 ` Yuri Khan
2015-02-09 4:23 ` Stefan Monnier
2015-02-09 16:05 ` Philipp Stephani
2015-02-09 17:12 ` Stefan Monnier
2015-02-10 10:30 ` Philipp Stephani
2015-02-27 19:44 ` Philipp Stephani
2015-03-13 22:08 ` Stefan Monnier
2015-03-15 18:33 ` Philipp Stephani
2015-03-16 13:29 ` Stefan Monnier
2015-03-24 15:14 ` Philipp Stephani
2015-03-24 21:55 ` Stefan Monnier
2015-04-08 21:04 ` Philipp Stephani
2015-04-09 2:10 ` Stefan Monnier
2015-04-09 15:48 ` Philipp Stephani
2015-04-09 18:47 ` Philipp Stephani
2015-04-09 20:07 ` Philipp Stephani [this message]
2015-04-13 14:57 ` Stefan Monnier
2015-04-13 22:17 ` Stefan Monnier
2015-04-17 2:40 ` Stefan Monnier
2015-04-17 6:25 ` Philipp Stephani
2015-04-17 6:29 ` Philipp Stephani
2015-04-17 13:52 ` Stefan Monnier
2015-04-17 14:00 ` Philipp Stephani
2016-03-29 10:15 ` Philipp Stephani
2015-03-28 18:59 ` Olaf Rogalsky
2015-03-29 3:39 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAArVCkRuhbo93iU0QvT0JB7bMb6c9PoPLxrf4Rg1x4tL_sERvQ@mail.gmail.com \
--to=p.stephani2@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=olaf.rogalsky@t-online.de \
--cc=yuri.v.khan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).