From 20fbde447cec1dc7978a2536e68aa29f416db6e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 May 2023 08:41:55 +0530 Subject: [PATCH] clipboard kitten: Dont set clipboard when getting clipboard The previous behavior meant getting the clipboard would first empty it if STDIN was null or empty which can easily happen when run non-interactively. Fixes #6302 --- docs/changelog.rst | 2 ++ kittens/clipboard/legacy.go | 4 +++- kittens/clipboard/main.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 00e9fbdf3..b8c9a049e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -48,6 +48,8 @@ Detailed list of changes - clipboard kitten: Fix a bug causing the last MIME type available on the clipboard not being recognized when pasting +- clipboard kitten: Dont set clipboard when getting clipboard in filter mode (:iss:`6302`) + - Fix regression in 0.28.0 causing color fringing when rendering in transparent windows on light backgrounds (:iss:`6209`) - show_key kitten: In kitty mode show the actual bytes sent by the terminal rather than a re-encoding of the parsed key event diff --git a/kittens/clipboard/legacy.go b/kittens/clipboard/legacy.go index f46699a2c..439b96456 100644 --- a/kittens/clipboard/legacy.go +++ b/kittens/clipboard/legacy.go @@ -99,7 +99,9 @@ func run_plain_text_loop(opts *Options) (err error) { stdin_is_tty := tty.IsTerminal(os.Stdin.Fd()) var data_src io.Reader var tempfile *os.File - if !stdin_is_tty { + if !stdin_is_tty && !opts.GetClipboard { + // we dont read STDIN when getting clipboard as it makes it hard to use the kitten in contexts where + // the user does not control STDIN such as being execed from other programs. data_src, tempfile, err = preread_stdin() if err != nil { return err diff --git a/kittens/clipboard/main.py b/kittens/clipboard/main.py index 536c3e936..08b16d776 100644 --- a/kittens/clipboard/main.py +++ b/kittens/clipboard/main.py @@ -50,7 +50,7 @@ Read or write to the system clipboard. This kitten operates most simply in :italic:`filter mode`. To set the clipboard text, pipe in the new text on :file:`STDIN`. Use the -:option:`--get-clipboard` option to output the current clipboard text content to +:option:`--get-clipboard` option to instead output the current clipboard text content to :file:`STDOUT`. Note that copying from the clipboard will cause a permission popup, see :opt:`clipboard_control` for details.