From 84fcabe5cfc453d485e90e96c53dcba5f88e1383 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 Jun 2019 07:47:34 +0530 Subject: [PATCH] Allow using the pipe command to send screen and scrollback contents directly to the clipboard See #1693 --- docs/changelog.rst | 3 +++ docs/pipe.rst | 4 ++++ kitty/boss.py | 5 +++++ kitty/glfw.c | 6 ++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index bcce5b67e..2e9ed45b8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -29,6 +29,9 @@ To update |kitty|, :doc:`follow the instructions `. option to have the kitten wait till copying to clipboard is complete (:iss:`1693`) +- Allow using the :doc:`pipe ` command to send screen and scrollback + contents directly to the clipboard (:iss:`1693`) + - Linux: Disable the Wayland backend on GNOME by default as GNOME has no support for server side decorations. Can be controlled by :opt:`linux_display_server`. diff --git a/docs/pipe.rst b/docs/pipe.rst index 4b3d68390..4e9e28213 100644 --- a/docs/pipe.rst +++ b/docs/pipe.rst @@ -43,6 +43,10 @@ You can choose where to run the pipe program: ``tab`` A new window in a new tab +``clipboard, primary`` + Copy the text directly to the clipboard. In this case the specified program + is not run, so use some dummy program name for it. + ``none`` Run it in the background diff --git a/kitty/boss.py b/kitty/boss.py index 6e6b145f7..b546b0812 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -910,6 +910,11 @@ class Boss: tm.new_tab(special_window=create_window(), cwd_from=cwd_from) elif dest == 'os_window': self._new_os_window(create_window(), cwd_from=cwd_from) + elif dest in ('clipboard', 'primary'): + env, stdin = self.process_stdin_source(stdin=source, window=window) + if stdin: + func = set_clipboard_string if dest == 'clipboard' else set_primary_selection + func(stdin) else: import subprocess env, stdin = self.process_stdin_source(stdin=source, window=window) diff --git a/kitty/glfw.c b/kitty/glfw.c index 1368ae249..dbd0100e7 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -843,7 +843,8 @@ get_content_scale_for_window(PYNOARG) { static PyObject* set_clipboard_string(PyObject UNUSED *self, PyObject *args) { char *title; - if(!PyArg_ParseTuple(args, "s", &title)) return NULL; + Py_ssize_t sz; + if(!PyArg_ParseTuple(args, "s#", &title, &sz)) return NULL; OSWindow *w = current_os_window(); if (w) glfwSetClipboardString(w->handle, title); Py_RETURN_NONE; @@ -987,7 +988,8 @@ get_primary_selection(PYNOARG) { static PyObject* set_primary_selection(PyObject UNUSED *self, PyObject *args) { char *text; - if (!PyArg_ParseTuple(args, "s", &text)) return NULL; + Py_ssize_t sz; + if (!PyArg_ParseTuple(args, "s#", &text, &sz)) return NULL; if (glfwSetPrimarySelectionString) { OSWindow *w = current_os_window(); if (w) glfwSetPrimarySelectionString(w->handle, text);