Unicode characters not rendering correctly #8495

Closed
opened 2026-01-31 01:30:54 +00:00 by claunia · 6 comments
Owner

Originally created by @willmcgugan on GitHub (May 22, 2020).

Environment

Microsoft Windows [Version 10.0.18363.720]
Terminal v1.0.1401.0

(It's a VM if that makes a difference)

Steps to reproduce

Install Rich python library (https://github.com/willmcgugan/rich), and run the following:

python -m rich.color

Expected behavior

Unicode box characters should render normally. The same output works with OSX / Linux.

Actual behavior

You should see broken unicode characters in the middle of the tables. Here are some examples:

Screen Shot 2020-05-22 at 14 38 00 Screen Shot 2020-05-22 at 14 38 25

If I was to hazard a guess I'd say that the utf-8 has been split over some internal buffer, and a multi-byte character was truncated at the boundary.

Originally created by @willmcgugan on GitHub (May 22, 2020). # Environment Microsoft Windows [Version 10.0.18363.720] Terminal v1.0.1401.0 (It's a VM if that makes a difference) # Steps to reproduce Install Rich python library (https://github.com/willmcgugan/rich), and run the following: ``` python -m rich.color ``` # Expected behavior Unicode box characters should render normally. The same output works with OSX / Linux. # Actual behavior You should see broken unicode characters in the middle of the tables. Here are some examples: <img width="1200" alt="Screen Shot 2020-05-22 at 14 38 00" src="https://user-images.githubusercontent.com/554369/82674016-99c3be80-9c3a-11ea-98ba-31638d3b4073.png"> <img width="1193" alt="Screen Shot 2020-05-22 at 14 38 25" src="https://user-images.githubusercontent.com/554369/82674029-9e887280-9c3a-11ea-82ce-4adacc75893f.png"> If I was to hazard a guess I'd say that the utf-8 has been split over some internal buffer, and a multi-byte character was truncated at the boundary.
claunia added the Resolution-ExternalNeeds-Tag-Fix labels 2026-01-31 01:30:55 +00:00
Author
Owner

@skyline75489 commented on GitHub (May 25, 2020):

This feels like a dup of #714 and/or #455

@skyline75489 commented on GitHub (May 25, 2020): This feels like a dup of #714 and/or #455
Author
Owner

@DHowett commented on GitHub (Jun 5, 2020):

This feels more like... hmm

We've got a bunch of validation that Terminal and Console properly buffer UTF-8 when it comes in.

This sound suspiciously like #386, which ended up being a CMD issue.

Is this a Python issue? I found PEP-0528, which discusses getting UTF-8 out of Python onto the console.

Of note: if you run it under WSL, it is beautiful. Same library, same terminal, different cpython runtime. 😄

@DHowett commented on GitHub (Jun 5, 2020): This feels more like... hmm We've got a bunch of validation that Terminal and Console properly buffer UTF-8 when it comes in. This sound suspiciously like #386, which ended up being a CMD issue. Is this a Python issue? I found [PEP-0528](https://www.python.org/dev/peps/pep-0528/), which discusses getting UTF-8 out of Python onto the console. Of note: if you run it under WSL, it is _beautiful_. Same library, same terminal, different cpython runtime. :smile:
Author
Owner

@willmcgugan commented on GitHub (Jun 6, 2020):

Very curious.

I've discovered that if I write the output to a file rather than to the terminal, and the use the type command to write the file to the terminal, the issue is no longer present.

But if I then open the same file in Python and write it to stdout, the issue appears. But only if I do the write in a single chunk. If I write in smaller chunks then it's fine.

I tried this on Python 3.8.1, 3.8.3, 3.9.0a6 and all had the same problem.

So it's clearly related to Python, but quite where the fault lies I'm not sure!

Let me know if there is anything I can do to help you diagnose. I could send you the output from the color table if that helps.

@willmcgugan commented on GitHub (Jun 6, 2020): Very curious. I've discovered that if I write the output to a file rather than to the terminal, and the use the `type` command to write the file to the terminal, the issue is no longer present. But if I then open the same file in Python and write it to stdout, the issue appears. But *only* if I do the write in a single chunk. If I write in smaller chunks then it's fine. I tried this on Python 3.8.1, 3.8.3, 3.9.0a6 and all had the same problem. So it's clearly related to Python, but quite where the fault lies I'm not sure! Let me know if there is anything I can do to help you diagnose. I could send you the output from the color table if that helps.
Author
Owner

@DHowett commented on GitHub (Jun 26, 2020):

So, I'm also unsure of how to proceed. I think the best way forward would be a bug filed on cpython (bugs.python.org). I'm concerned about their buffering, given your remark about doing the write in a single chunk. 😄

There's a bit of stuff here-
578c3955e0/Modules/_io/winconsoleio.c (L979-L988)
-that might be of interest. This is the only place they call WriteConsoleW.

I'm gonna close this one out as, perhaps, something we don't have too much control over.

@DHowett commented on GitHub (Jun 26, 2020): So, I'm also unsure of how to proceed. I think the best way forward would be a bug filed on cpython (bugs.python.org). I'm concerned about their buffering, given your remark about doing the write in a single chunk. :smile: There's a bit of stuff here- https://github.com/python/cpython/blob/578c3955e0222ec7b3146197467fbb0fcfae12fe/Modules/_io/winconsoleio.c#L979-L988 -that might be of interest. This is the only place they call WriteConsoleW. I'm gonna close this one out as, perhaps, something we don't have too much control over.
Author
Owner

@DHowett commented on GitHub (Jun 26, 2020):

BINGO!

/dup https://bugs.python.org/issue37871

@DHowett commented on GitHub (Jun 26, 2020): BINGO! /dup https://bugs.python.org/issue37871
Author
Owner

@ghost commented on GitHub (Jun 26, 2020):

Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!

@ghost commented on GitHub (Jun 26, 2020): Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8495