zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
21.67k stars 656 forks source link

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

Open fansari opened 2 years ago

fansari commented 2 years ago

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

imsnif commented 2 years ago

@tlinford - any quick ideas?

tlinford commented 2 years ago

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.

imsnif commented 2 years ago

@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?

fansari commented 2 years ago

This is my config.yaml:

---
  pane_frames: false
  mouse_mode: false
tlinford commented 2 years ago

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

fansari commented 2 years ago

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".

tlinford commented 2 years ago

is wl-copy installed?

fansari commented 2 years ago

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.

tlinford commented 2 years ago

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.

fansari commented 2 years ago

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.

tlinford commented 2 years ago

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

fansari commented 2 years ago

I have tested this now.

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

tlinford commented 2 years ago

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.

camillebernier commented 2 years ago

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 ?

tlinford commented 2 years ago

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.

camillebernier commented 2 years ago

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 ?

imsnif commented 2 years ago

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?

camillebernier commented 2 years ago

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 ?

imsnif commented 2 years ago

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?