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

Extra newline when copying line with wide glyph on the edge #11739

Open
Tracked by #5800
Kagami opened this issue Nov 11, 2021 · 6 comments
Open
Tracked by #5800

Extra newline when copying line with wide glyph on the edge #11739

Kagami opened this issue Nov 11, 2021 · 6 comments
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Milestone

Comments

@Kagami
Copy link

Kagami commented Nov 11, 2021

Windows Terminal version (or Windows build number)

10.0.19043.1348, 1.12.2931.0

Other Software

Ubuntu 21.04 in WSL

Steps to reproduce

  1. Open tab with some WSL distro, shouldn't matter which.

  2. Create python3 file with the following content:

import os
import sys
cols = os.get_terminal_size().columns
sys.stdout.buffer.write(b'a'*(cols-1))
sys.stdout.buffer.write(b'\xea\xb0\x9c')
  1. Run it:
python3 1.py
  1. Copy output with the mouse and paste to some editor.

Expected Behavior

There should be only single line of text.

Actual Behavior

There're two lines of text, see screenshots.

1
2

The problem doesn't appear if that 3-byte symbol is not on the edge of the line. Also 2-byte symbols work fine too.

@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 Nov 11, 2021
@zadjii-msft
Copy link
Member

Hmm. Doesn't repro in conhost. So this is probably a conpty wrapping bug. Probably related to #5800 in some way I don't fully know yet. Thanks for the minimal repro!

@zadjii-msft zadjii-msft added Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty labels Nov 16, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Nov 16, 2021
@zadjii-msft zadjii-msft added this to the Terminal v2.0 milestone Nov 16, 2021
@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 17, 2021
@Kagami
Copy link
Author

Kagami commented Dec 3, 2021

GNOME Terminal in native Linux also wraps the line -- as it should, I think.

The problem is not the line wrapping, it's the extra newline when I copy the output to the clipboard.

This problem doesn't happen with two-byte symbols (single column), e.g.:

sys.stdout.buffer.write(b'a'*(cols-1))
sys.stdout.buffer.write('тест'.encode('utf-8'))

a

@Kagami
Copy link
Author

Kagami commented Dec 3, 2021

Works fine in this case too:

sys.stdout.buffer.write(b'a'*(cols-2))
sys.stdout.buffer.write(b'\xea\xb0\x9c')
sys.stdout.buffer.write(b'\xea\xb0\x9c')

It seems be related to the fact that there's only 1 column left on the current line but the character takes 2 columns.

image

@eryksun
Copy link

eryksun commented Dec 3, 2021

The problem is not the line wrapping, it's the extra newline when I copy the output to the clipboard.

Sorry, I misunderstood that the problem was the newline itself in the output. I see now that it shouldn't be there and normally isn't, except when a wide glyph is wrapped at the edge.

To me, the following example more clearly emphasizes that the character is known to be a wide glyph that prints in two columns (hence dividing the column count by 2), and that it's expected to wrap in the terminal by one character. The bug is just that the terminal adds a line-feed (LF) character where it wraps the line for display.

>>> os.get_terminal_size().columns
133
>>> print('\uac1c' * (os.get_terminal_size().columns // 2 + 1))
개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개


>>> os.get_terminal_size().columns
132
>>> print('\uac1c' * (os.get_terminal_size().columns // 2 + 1))
개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개

The output copied from the terminal with an odd number of columns (133) should not have the LF before the last "개" character. This example works fine with an even number of columns, for which a wide glyph doesn't straddle the edge.

Now that I know what I'm looking for, I see that conhost in Windows 10 and 11 is also wrong, but in a different way. For example:

>>> os.get_terminal_size().columns
133
>>> print('\uac1c' * (os.get_terminal_size().columns // 2 + 1))
개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개 

>>> os.get_terminal_size().columns
132
>>> print('\uac1c' * (os.get_terminal_size().columns // 2 + 1))
개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개개

That's an ASCII space (0x20) inserted where the line was wrapped for display. It's not present when the line wrap occurs on a single-column character, or for this example when there is an even number of columns.

@Kagami Kagami changed the title Extra newline when copying line with 3-byte UTF-8 character on the edge Extra newline when copying line with wide glyph on the edge Dec 3, 2021
@Kagami
Copy link
Author

Kagami commented Dec 3, 2021

Thanks for clarification, I modified issue's title accordingly.

@eryksun
Copy link

eryksun commented Dec 3, 2021

I updated my last comment to use the same screen sizes in Windows Terminal and conhost, and also to show that the bug only occurs for me when the number of columns in the terminal is odd, which causes a wide glyph to straddle the edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

No branches or pull requests

4 participants