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

Multi-line copies from tmux scrollback buffer strips newlines #13898

Closed
mrjoel opened this issue Sep 1, 2022 · 5 comments
Closed

Multi-line copies from tmux scrollback buffer strips newlines #13898

mrjoel opened this issue Sep 1, 2022 · 5 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@mrjoel
Copy link

mrjoel commented Sep 1, 2022

Windows Terminal version

1.14.2281.0

Windows build number

10.0.19044.0

Other Software

tmux 3.3a-1~bpo11+1 (inside WSL2, from Debian bullseye-backports)

Steps to reproduce

  • From within a tmux session, execute something which generates multiple terminal heights in output
  • Working path
    • from Terminal, select to copy some multi-range text at the bottom of output
    • paste text into target application of choice, note that newlines are preserved - good
  • Error path
    • enter scrollback mode in tmux, scroll up to earlier output
    • from Terminal, select to copy some multi-range text towards the top of the output
    • paste text into target application of choice, note that all newlines are stripped and the output is combined as a single long line - bad

Scrolling up a full page or more is the easiest way to observe this, but careful observation shows that when scrolling less than a page up the scrollback buffer (so some originally viewable text is retained), copying the text that was originally viewable retains newlines, while copying text retrieved from the scrollback buffer strips the newlines. In fact, doing a multi-line selection across the boundary of original view pane results in stripped newlines only up until the original viewable content is encountered, at which point newlines are retained.

Expected Behavior

Copying multi-line selections through Terminal always retains newlines, even from alternate buffer and tmux scrollback buffer

Actual Behavior

New lines are stripped from multi-line selection copied text

@mrjoel mrjoel added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Sep 1, 2022
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 1, 2022
@mrjoel mrjoel changed the title Select copying when viewing tmux scrollback buffer strips newlines Multi-line copies from tmux scrollback buffer strips newlines Sep 1, 2022
@EBADBEEF
Copy link

EBADBEEF commented Sep 2, 2022

There are a few fuzzy things that probably need to be described. I have been pulling my hair out on this one too...

  • Do you have "Automatically copy selection to clipboard" (copyOnSelect)?
  • Do you have mouse support enabled in tmux?
  • Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)?
  • How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button?
  • What version of windows ("ver" command) and terminal? (for me it's win 10.0.22000.856, terminal 1.14.2282.0) (edit: I see you already provided that info)

In my testing, holding shift while right clicking always strips out the newlines, even in a cmd.exe shell!

If I select the text with shift+lmb then copy with the keyboard shortcut everything is good. Also, doing a block select works (holding alt+shift).

@mrjoel
Copy link
Author

mrjoel commented Sep 2, 2022

Do you have "Automatically copy selection to clipboard" (copyOnSelect)?
Do you have mouse support enabled in tmux?
Follow-up, do you hold shift while selecting selecting the text (to avoid tmux grabbing the mouse click)?

Yes, yes, and yes

How exactly are you copying? Right mouse button, ctrl+insert, ctrl+shift+c? Are you holding shift while clicking the right mouse button?

I hold shift and select with the left mouse button. Once text is selected, copyOnSelect does its thing and I paste in my destination of choice. In order to copy again, I have to press Esc to clear the previous selection and then again hold shift and select with left mouse button.

Anything with the right mouse button attempts to paste copied content.

@EBADBEEF
Copy link

EBADBEEF commented Sep 3, 2022

I guess my issue is different, then! If you search through the terminal issues for "paste" you will find tons of problems about newlines. But out of solidarity I tried to reproduce your issue :-). I installed a fresh debian in WSL. First I tried stretch tmux (2.3-4) but failed to reproduce. Then I added bullseye-backports to /etc/apt/sources.list and updated:

deb http://deb.debian.org/debian bullseye-backports main contrib non-free
deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free
$ sudo apt update && sudo apt upgrade

My debian-foo is rusty so I'm not really sure how you got 3.3a-1~bpo11+1 installed into stretch. I assume you build it from source? So I tried:

$ apt source -t bullseye-backports tmux
$ sudo apt build-dep -t bullseye-backports tmux
--> failed with  "builddeps:tmux : Depends: debhelper-compat (= 13) but it is not installable"
$ sudo apt install debhelper libevent-dev libncurses5-dev libutempter-dev pkg-config build-essential
$ cd tmux-3.3a
$ dpkg-buildpackage
--> failed with same debhelper-compat error
(so I manually built)
$ ./configure --enable-utempter && make

How I tried to reproduce:

  • My ~/.tmux.conf contains just set-option -g mouse on
  • Changed my windows terminal to enable copyOnSelect
  • I started tmux and generated pages of output with while [ 1 ]; do echo -e 'line1\nline2\nline3'; done
  • I entered scrollback mode with ctrl-B + [, scrolled up with pgup (see something like [672/1850] in the corner)
  • Copied multiple lines with shift + left mouse button drag
  • Hit ctrl-c to leave tmux scrollback mode
  • Typed echo '<PASTE>' | xxd and see the newlines are in the output correctly (not necessary to use xxd, but it is easy to spot runs of 20s).
  • My TERM before entering tmux is xterm-256color, inside tmux is screen-256color
  • My shell is bash
  • I do note that our Windows and Windows Terminal versions are different.
  • Sometimes I get garbled output when looking at my echo command line + paste in bash, but the output is correct. Weird. Looks like line1> line3.

The only time I got added spaces was when I accidentally copied the line counter where tmux prints [n/total] in the upper right corner. Hah! I tried mixing alternate screen and not by doing lots of echo then entering a long man page (man iptables) and then scrolling back up to the prints in tmux. But still no luck.

Maybe make a video? You can record pretty quickly with xbox game bar (win+g key). Good luck!

@zadjii-msft
Copy link
Member

zadjii-msft commented Sep 8, 2022

Pretty sure this looks like /dup #8976

edit: yes it definitely is

@ghost
Copy link

ghost commented Sep 8, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Sep 8, 2022
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 8, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants