zellij icon indicating copy to clipboard operation
zellij copied to clipboard

copy&paste in Gnome terminal adds spaces at the end of each line

Open fansari opened this issue 3 years ago • 19 comments
trafficstars

When I am in a Gnome terminal and copy a portion of text (several lines) and paste in somewhere (I have tested nano and vim) there are always spaces after the line ends (corresponding to the window width).

What I can do as a workaround is to go to the last non-space character of the line enter a new line and then delete the next line (which then consists only out ouf spaces of course).

I would like to be able to copy&paste without having to deal with each line after the pasting to get rid of all these extra spaces.

When I do the same copy&paste without zellij in a Gnome terminal I don't have this issue.

With Windows 10 with PuTTY and zellij I also don't have this issue.

Tested with : gnome-terminal-3.44.0-1.fc36.x86_64 zellij 0.28.1

fansari avatar Apr 16 '22 12:04 fansari

@tlinford - any quick ideas?

imsnif avatar Apr 25 '22 15:04 imsnif

I'm assuming this is happening with mouse_mode off and pane frames removed, @fansari can you confirm?

@imsnif - took a stab at logging serialized_output in Screen::render, here's an excerpt that seems explanatory:

\u{1b}[?25l\u{1b}[3;2H\u{1b}[m\u{1b}[m\u{1b}]8;;\u{1b}\\Welcome to fish, the friendly interactive shell                                                                 \u{1b}[4;2H\u{1b}[m\u{1b}[m\u{1b}]8;;\u{1b}\\Type `help` for instructions on how to use fish                                                                 \u{1b}[5;2H\u{1b}[m\u{1b}[m\u{1b}]8;;\u{1b}

basically it seems that for each line, spaces get output until the pane width is reached.

tlinford avatar Apr 25 '22 17:04 tlinford

@imsnif - took a stab at logging serialized_output in Screen::render, here's an excerpt that seems explanatory:

Maybe it would be a good idea to copy from the terminal buffer rather than the rendered lines?

imsnif avatar Apr 26 '22 11:04 imsnif

This is my config.yaml:

---
  pane_frames: false
  mouse_mode: false

fansari avatar Apr 26 '22 16:04 fansari

Thanks @fansari , I discussed this a little with @imsnif - and unfortunately there is not much we can do about this issue at the moment, we rely on outputting the spaces that you are seeing when copying,

If you are not opposed to re-enabling mouse mode you should be able to get copy and paste working in gnome-terminal by setting the copy_command option (and installing the corresponding utility for your environment), see this snippet for reference: https://github.com/zellij-org/zellij/blob/bba12afbce4d9f9ae3881b3fe36d77dd1fec3fb8/example/default.yaml#L524-L531

tlinford avatar Apr 26 '22 16:04 tlinford

I have tried now this:

---
  pane_frames: false
  mouse_mode: true
  copy_command: wl-copy

When I now select text I get this message: "Error using the system clipboard".

fansari avatar Apr 26 '22 16:04 fansari

is wl-copy installed?

tlinford avatar Apr 26 '22 16:04 tlinford

It was not installed. I have now installed the package "wl-clipboard" and now it works - well somehow.

I can now copy the content in a graphical editor like Atom for example.

But I cannot copy it inside of nano.

Both should work.

I can of course copy it again in Atom and then paste it into nano. This is more a workaround than a nice solution.

fansari avatar Apr 26 '22 16:04 fansari

How are you pasting into nano? Just tested with ctrl+shift+v, or from gnome-terminal edit menu, using the same setup and it worked fine for me.

tlinford avatar Apr 26 '22 17:04 tlinford

Yes - you are right. This works. I used "shift+insert" which normally works - but obviously as I see now not here. Also right mouse click paste does not work. But at least ctrl+shift+v works.

fansari avatar Apr 30 '22 13:04 fansari

So, there are a couple of things going on here:

  • In linux there are normally two different clipboards, primary and clipboard: https://wiki.archlinux.org/title/clipboard#Selections. So for example in gnome-terminal ctrl+shift+v copies from clipboard, while shift+insert (or middle mouse click) copies from primary. You could for example change the above config to use copy_command: wl-copy -p to instruct wl-copy to use the primary selection and then the zellij selection would be available via shift+insert, but not with ctrl+shift+v.

  • Regarding right click paste - I believe you are not seeing the context menu pop up when right clicking? That is to be expected with mouse_mode enabled, since mouse events are not being handled by gnome-terminal anymore, but rather forwarded to zellij (this is not zellij specific, any terminal application with mouse support will do this). This can be avoided, by holding down shift and clicking with the mouse the mouse events will be handled by the terminal emulator.

tlinford avatar Apr 30 '22 16:04 tlinford

I have tested this now.

  • wl-copy -p works. When I configure it like this I can use shift+insert again.
  • I don't get the context menu. With holding shift I get the menu and it works when I again use wl-copy without -p.

So this means I have to decide whether I want to copy from primary or clipboard.

fansari avatar May 02 '22 15:05 fansari

So this means I have to decide whether I want to copy from primary or clipboard.

For now yes - definitely something that can still be improved though.

tlinford avatar May 02 '22 16:05 tlinford

Hello, I have (kind of) the same issue.

Here is my config.yaml:

---
  pane_frames: false
  mouse_mode: false

For example if I try to copy/paste my ssh key push for example here is what I got :

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNsjuHOxkec/ZAgdcYCcW1pkHl136m/vmiCMlsxxWQ6vQBjhqmjBC2Yh7M0mUaKzkdY+bUeDVSRjNCnx/W90UrPzBdGOn8CCR2YPiDocm0YV5lhu2PqzFb+i8Hk7UwmaEii6wOFVF8tpFj0Rg9g9SkgtpEBks2xX7okQ5vB+vZGHEZvNLanaKf6oVumgI4w/Ba58a0cUJRaFaaX32+UXM/wpD2zakdreIcqN6JKNaksZRv
nLTCxTx7/qPQ6S3WF8u+HXyMtzonWVg+R74Xn2HfC/1A8dA7EcZiAsBRrbpuGpc0tWNiEZjEiM9X7S3LVrib89V06fkvyH8eSuIlOyMf0sT9tkbQvkvhOxr7QSi1B1BK9OH0CxsNtQoQLNPD2N/NyzjSrpnRobt4VJJJDKJBDLNVJHKkNmAF6FINQVuhn9grp0fplc88Y+Z9Okx2LL256fgr9bRC1elwQzHDWBqZsBnOcq60Mlf7ilsjjuoH+EiZ2TllqXT2xrnRtA1ncYSw
cIKNClMcI9JlcsOp+vXaat88YKZ8aazd0= camiyo

There are always spaces after the line ends (corresponding to the window width) And here is the original key :

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNsjuHOxkec/ZAgdcYCcW1pkHl136m/vmiCMlsxxWQ6vQBjhqmjBC2Yh7M0mUaKzkdY+bUeDVSRjNCnx/W90UrPzBdGOn8CCR2YPiDocm0YV5lhu2PqzFb+i8Hk7UwmaEii6wOFVF8tpFj0Rg9g9SkgtpEBks2xX7okQ5vB+vZGHEZvNLanaKf6oVumgI4w/Ba58a0cUJRaFaaX32+UXM/wpD2zakdreIcqN6JKNaksZRvnLTCxTx7/qPQ6S3WF8u+HXyMtzonWVg+R74Xn2HfC/1A8dA7EcZiAsBRrbpuGpc0tWNiEZjEiM9X7S3LVrib89V06fkvyH8eSuIlOyMf0sT9tkbQvkvhOxr7QSi1B1BK9OH0CxsNtQoQLNPD2N/NyzjSrpnRobt4VJJJDKJBDLNVJHKkNmAF6FINQVuhn9grp0fplc88Y+Z9Okx2LL256fgr9bRC1elwQzHDWBqZsBnOcq60Mlf7ilsjjuoH+EiZ2TllqXT2xrnRtA1ncYSwcIKNClMcI9JlcsOp+vXaat88YKZ8aazd0= camiyo

I tried with wl-copy but I got the same problem.

Tested with: zellij 0.30.0 alacritty 0.11.0-dev (without zellij I do not have the problem) Ubuntu 22.04

Any idea ?

camillebernier avatar Jul 22 '22 07:07 camillebernier

I tried with wl-copy but I got the same problem.

The wl-copy method currently relies on selecting text with the native zellij mechanism, and that requires mouse_mode to be on, not sure if you also changed that?

Since you are using alacritty you wouldn't even need to use the copy-command option, just having mouse mode enabled should be sufficient.

tlinford avatar Jul 22 '22 07:07 tlinford

Ah ok I understand, but I want to keep the mouse mode disabled because I don't like it... Any idea about how I can get rid of this space problem with the mouse_mode disabled ? Maybe I should create another issue ?

camillebernier avatar Jul 25 '22 10:07 camillebernier

Hey @Camiyo - mouse_mode is what allows Zellij to copy only the relevant parts of the text in your terminal and not eg. the pane frames or the contents of other panes (imagine you have for example two panes open side-by-side).

I understand you don't like it, but it's unfortunately a "necessary evil" in this case. The closest thing we can do to what you ask is make it possible assuming only one pane on screen at the same time, without a top bar. That solution will require quite some work on our part, and IMO it's not a very big UX improvement... or please correct me if you disagree on the latter?

imsnif avatar Jul 25 '22 15:07 imsnif

Ok I understand. Is there a way to switch between mouse_mode enabled/disabled in live (maybe with a keybinding) ? I mean without changing in config.yml and restart zellij ?

camillebernier avatar Jul 25 '22 15:07 camillebernier

Is there a way to switch between mouse_mode enabled/disabled in live (maybe with a keybinding) ? I mean without changing in config.yml and restart zellij ?

Hum, that's an interesting idea. There is no way to do this now, but it might be a cool feature to add. Would you like to open a separate issue for this?

imsnif avatar Jul 25 '22 19:07 imsnif