-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Window line-wrapping can cause colored output to break copied text #16166
Comments
Alright, I've figured it out. And as always, it's a very very very specific edge case. It's when I use bat (aka. batcat) to output colored text, with certain flags set.
It's worth noting that it works fine (i.e. "as expected") if the window is wide enough to not wrap when the command is run. If I resize the window later, the problem is not there. Something that really surprises me is that piping the output via |
Can you try this again on Terminal Preview, v1.19/? (manual download link: https://github.com/microsoft/terminal/releases/tag/v1.19.2831.0) We just recently re-wrote how resize/reflow works, and I have a feeling that it may have just fixed this |
I don't think v1.19 will make any difference. If you run I also noticed there's an issue in their bug tracker which sounds like it might be related (see sharkdp/bat#1740). |
Thanks for the suggestion. I just tried with Preview version 1.19.2682.0 and it had the exact same behavior, unfortunately.
Interesting! That bug does indeed sound very similar to my problems. It is beyond be how there can be a line wrap that affects copying but not resizing. Do you have any clue how that's possible? |
The fact that the resizing "works" for you is actually a bug. When you have a line that's the exact width of the screen, it is mistakenly considered to be wrapping when the screen is resized (see issue #3088). That was supposed to have been fixed recently, but it still doesn't seem to be working correctly in Windows Terminal. |
Can you try repro'ing this with the debug tap to get a trace of all the input and output? Once the bug starts occurring, send us a screenshot/copy-paste of the output and we might be able to figure out what the Terminal thinks it's getting here. |
It looks like there was a typo in Mike's link. It should be: |
(thanks - forgot that I had fixed that typo but not the links in my quick replies 🤦) |
Here you go! :)
|
Oh whoops I clearly never hit enter on my reply last week. The debug tap obviously showed a manual line break, that's what we're trying to figure out 🤦 Can you try with That'll actually capture what was emitted straight from the application, rather than what conpty re-emitted. (thanks for your patience) |
Thanks for the help! typescript without debug tap
debug tap output, without script
|
Looks like the bat utility inserts hard line breaks. This issue on the bat repository might be helpful: sharkdp/bat#897 Thanks for filing! |
@carlos-zamora please read the above. |
At the very least, there are a couple issues here.
for 1
This is because for 2Now, we should not treat hard wrapped lines as wrapped text under any circumstances. However, we used to have an issue where text would unwrap on resize even though we knew it had a hard line break1 I can reproduce this in 1.17 (where you originally filed the bug): ... and in 1.18 ... but not in 1.19 (preview) or 1.20 (canary): If I try your repro from (window width 76 as specified in repro) That is what @j4james was saying was a bug. Resize should have never unwrapped the lines, which would have made it more obvious that Footnotes
|
@DHowett FYI, I can still reproduce the bug with the bash test case from issue #3088 in version 1.19.2682.0 of Windows Terminal. However, your PowerShell test case does not reproduce the bug for me. Looking at the debug tap, it seems that conpty is not actually writing out the expected |
@j4james I cannot reproduce it in 1.19.3172.0. Pretty sure I did reproduce it in Terminal Preview before, but maybe not. ¯\_(ツ)_/¯ EDIT: I think I know what I did wrong last time I "reproduced" it in Preview! I think that was before I realized that |
Windows Terminal version
1.17.11461.0
Windows build number
10.0.22621.0
Other Software
bat 0.19.0
Steps to reproduce
I have found this very specific scenario for reproducing the issue reliably:
Install bat.
Create
EXAMPLE.md
with the following contents (including the markdown code fence, because we want syntax highlighting to color the output):Resize the terminal to be narrower than that long
echo
line.Run the following:
Copy the output.
Paste the output in a wider window.
It's worth noting that it works fine (i.e. "as expected") if the window is wide enough to not wrap when the command is run. If I resize the window later, the problem is not there.
Something that really surprises me is that piping the output via
cat
fixes the issue while looking exactly the same visually:This bug is very similar to, or actually the same as, #5113.
Expected Behavior
For clarity, I think we need to distinguish between the line breaks introduced by Windows Terminal for the purposes of displaying a long line in a wrapped format and the line breaks that are part of the original string. I will call them wrapping line breaks and string line breaks respectively.
When copying a string from the terminal, I expect to copy the string line breaks but not the wrapping line breaks, so that when I paste it I get the "original" string (not the one with line wrappings).
Actual Behavior
When I copy text under these circumstances, it keeps the wrapping line breaks as well as he string line breaks.
The text was updated successfully, but these errors were encountered: