Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy/paste not working #27

Closed
sdfux opened this issue Apr 10, 2023 · 20 comments
Closed

Copy/paste not working #27

sdfux opened this issue Apr 10, 2023 · 20 comments

Comments

@sdfux
Copy link

sdfux commented Apr 10, 2023

I just installed kitty_grab but is not working

-Press mapped key
-Kitty flashes
-Change title to "grab"
-Select text
-Press enter
-But when trying to paste, it paste what is already on de clipboard no the selection I just made.

$ kitty -v kitty 0.27.1 created by Kovid Goyal
Windows system X11

@yurikhan
Copy link
Owner

Hm.

Does clipboard generally work for you in kitty? For example, if you select text with the mouse and press Ctrl+Shift+c, does it copy? (I am asking this as a diagnostic step, not suggesting a workaround.)

When you press Enter after selecting text from kitty_grab, does the title change back from “Grab”?

If you run kitty from another terminal and perform all of the above up to and including pressing Enter, do you get any error output in the first terminal? If you do, please post it here.

@sdfux
Copy link
Author

sdfux commented Apr 10, 2023

Hi Yurikhan,

Yes, Ctrl+Shift+c works fine.
Yes, after pressing Enter it change back from "Grab"
No error output on copy/paste, after opening kitty from other terminal the only I get is this:
ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust
but no errors in any of the steps described above.

@yurikhan
Copy link
Owner

Okay, next step. In the _grab_ui.py file, find the line starting with def handle_result. Add a debug output statement so it looks like this:

def handle_result(args: List[str], result: 'ResultDict',
                  target_window_id: WindowId, boss: Boss) -> None:
    print(result)  # ← add this
    if 'copy' in result:
        set_clipboard_string(result['copy'])

Now repeat the copying (in kitty started from another terminal).

When you press Enter after selecting some text, you should see the following in the first terminal:

{'copy': '…your selected text…'}

Do you?

@sdfux
Copy link
Author

sdfux commented Apr 10, 2023

I did an ls -ltr
And after selecting the last row and pressing Enter this is what I get

{'copy': '-rw-r--r-- 1 gabo gabo 25400 Apr 10 10:52 _grab_ui.py'}

@yurikhan
Copy link
Owner

So basically the correct data gets almost to the end of kitty_grab and up to the kitty’s API function to set clipboard contents, but that last step does not work for some reason.

Last ditch attempt, does it work for you if you change it this way?

def handle_result(args: List[str], result: 'ResultDict',
                  target_window_id: WindowId, boss: Boss) -> None:
    if 'copy' in result:
        boss.clipboard.set_text(result['copy'])

@sdfux
Copy link
Author

sdfux commented Apr 10, 2023

Sadly, no.

@yurikhan
Copy link
Owner

Does it work for you in past versions of Kitty? What is the last version that works?

(It works for me on v0.26.5, and building v0.27.1 requires(?) Go 1.20 which is not packaged for Ubuntu 22.04, and I’m reluctant to install bleeding edge, so I can’t check easily.)

@sdfux
Copy link
Author

sdfux commented Apr 10, 2023

Sorry, I used to use urxvt, but I was recommended to try kitty, and this is something I use a lot on urxvt.

Let me check if I find how to install the 0.26.5 version and I will let you know.

@sdfux
Copy link
Author

sdfux commented Apr 10, 2023

I already installed 0.26.5 but still not working

Running kitty from another terminal I get this

[100 12:28:42.768541] Ignoring unknown config key: show_hyperlink_targets
[100 12:28:42.770935] Ignoring unknown config key: tab_title_max_length
[100 12:28:42.771572] Ignoring unknown config key: background_tint_gaps
ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust

Edit:
Already clean the kitty.conf but still not working

Using "Debian GNU/Linux 11 (bullseye)"

@yurikhan
Copy link
Owner

I’m stumped, calling @kovidgoyal.

TL;DR: I’m calling kitty.clipboard.set_clipboard_string with a string argument and we have confirmed with the OP that the argument has the expected value; but the content does not make it to the clipboard, on both 0.27.1 and 0.26.5 on Debian 11. For me, 0.26.5 on Ubuntu 20.04 works as expected; didn’t test 0.27.1.

What could we do to debug this further?

@kovidgoyal
Copy link

I dont see how that's possible. Either copying in general is not working
or calling set_clipboard_string() must work since it is what is used by copying in general, as easily verified in the copy_to_clipboard()
function in window.py

Most likely there are multiple calls to copy that are ending with setting the clipboard to the empty string or the OP is not doing what he thinks he is doing.

@kovidgoyal
Copy link

Although I have to ask why is copy_string_to_clipbaord being used at all? Shouldn't this kitten just be passing the text to kitty to copy via OSC 52?

@yurikhan
Copy link
Owner

@kovidgoyal What are the advantages and disadvantages of the two approaches? As far as I can see:

OSC 52:

  • (+) stable API
  • (­­­−) possibly length-limited
  • (−) gated by clipboard_control write-clipboard
  • (0) works over SSH but that’s not relevant because kittens run locally

calling a method:

  • (+) slightly faster as it avoids a base64 encode/decode and protocol parse

@yurikhan
Copy link
Owner

yurikhan commented Apr 11, 2023

@sdfux Please try the osc52 branch. You will have to make sure your clipboard_control config value includes write-clipboard.

@kovidgoyal
Copy link

That's more or less correct, the main reason I asked is that I assume
this kitten is running as a child process reading the screen contents on
stdin. In such a scenario its just easier to use OSC52 in the child
process itself, this allows for instance copying multiple things without
quitting the child process.

@yurikhan
Copy link
Owner

I have not considered the use case to copy multiple things. In my head, the user wants to invoke the kitten, select some text, copy it and go on working, maybe pasting it into the same session it was copied from. To copy something else, the user re-invokes the kitten.

Although I can see how one might want to keep the kitten active, copy something out of it and paste into another application, repeat this multiple times without losing one’s position in the scrollback.

@sdfux
Copy link
Author

sdfux commented Apr 11, 2023

Hi all,
I'm using the osc52 branch, and it is working now.

Thanks for your help and sorry for the late response since when the comments arrive it was 2am here were I live.

@sdfux sdfux closed this as completed Apr 11, 2023
@pallaswept
Copy link

pallaswept commented Aug 28, 2023

I also had a failure to copy. It worked fine so long as I never went past the top of the screen into the scrollback buffer.

OSC52 branch is working as far as copy and paste goes, although it does something weird with the highlighted text.:

image

This is what it pasted after that:

image

I'm using kitty especially because of its OSC52 support which is needed for copyQ on wayland.

@yurikhan
Copy link
Owner

I think weird behavior in presence of tab characters is a separate bug (#28).

@pallaswept
Copy link

I think weird behavior in presence of tab characters is a separate bug (#28).

🤦 I didn't even notice, of course it is the tabs. Sorry, I should have opened a separate case. My bad, and thank you for helping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants