How to set UTF-8 in Windows Terminal #16150

Closed
opened 2026-01-31 04:58:59 +00:00 by claunia · 7 comments
Owner

Originally created by @Jasper-zh on GitHub (Dec 16, 2021).

CHCP 65001 has no effect, how do I set the terminal to UTF-8

Originally created by @Jasper-zh on GitHub (Dec 16, 2021). CHCP 65001 has no effect, how do I set the terminal to UTF-8
Author
Owner

@237dmitry commented on GitHub (Dec 16, 2021):

I set utf-8 system wide in intl.cpl

ss-20211216093122

@237dmitry commented on GitHub (Dec 16, 2021): I set utf-8 system wide in intl.cpl ![ss-20211216093122](https://user-images.githubusercontent.com/78153320/146320017-02e4d3c6-f49f-448b-b6e3-8e293a2a50ba.png)
Author
Owner

@zadjii-msft commented on GitHub (Dec 16, 2021):

You gotta give us more details - what shell you're using, what OS version, what Terminal version, etc. etc.

@zadjii-msft commented on GitHub (Dec 16, 2021): You gotta give us more details - what shell you're using, what OS version, what Terminal version, etc. etc.
Author
Owner

@eryksun commented on GitHub (Dec 16, 2021):

With code page 65001, even Terminal Preview 1.12.2931.0 reads non-ASCII characters as null bytes. Who knows when Terminal and conhost will support UTF-8 properly. For now, implement a layer that translates between UTF-8 and UTF-16, and call ReadConsoleW() and WriteConsoleW(). We implemented that for Python a long time ago. Problem solved.

@eryksun commented on GitHub (Dec 16, 2021): With code page 65001, even Terminal Preview 1.12.2931.0 reads non-ASCII characters as null bytes. Who knows when Terminal and conhost will support UTF-8 properly. For now, implement a layer that translates between UTF-8 and UTF-16, and call `ReadConsoleW()` and `WriteConsoleW()`. We implemented that for Python a long time ago. Problem solved.
Author
Owner

@ghost commented on GitHub (Dec 20, 2021):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Dec 20, 2021): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@Jasper-zh commented on GitHub (Dec 22, 2021):

image

This is my current version of the system.
Windows terminal actually uses cmd or powershell.
I usually use Powershell.

Untitled
Untitled
Cmd can be made effective by chcp 65001.
But powshell uses CHCP65001 to no effect, even though the actual CHCP output code is already 65001. However, utF-8 Chinese characters are still garbled.
The current solution is to turn on utf-8 in the language set by the system. This does work, but some old applications may not support utf8, so there will be some problems.

@Jasper-zh commented on GitHub (Dec 22, 2021): ![image](https://user-images.githubusercontent.com/45052303/147051234-d8d250dd-8773-47d1-bc41-50273a315649.png) This is my current version of the system. Windows terminal actually uses cmd or powershell. I usually use Powershell. ![Untitled](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/8f272ed5-1342-4059-b0bd-1dfd548b358a/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20211222%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20211222T073303Z&X-Amz-Expires=86400&X-Amz-Signature=abee561e6e56a783c858cb0a5a96bf9b990d20f76e765efe7fc9559a465b87b1&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22Untitled.png%22&x-id=GetObject) ![Untitled](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/d148c828-b1af-4e82-8053-17d2a84ab31e/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20211222%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20211222T073343Z&X-Amz-Expires=86400&X-Amz-Signature=0a5569406f525d10ddfe4490a6678055bb2125bba8d77c1941a5d6a4e8748cee&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22Untitled.png%22&x-id=GetObject) **Cmd can be made effective by chcp 65001.** **But powshell uses CHCP65001 to no effect, even though the actual CHCP output code is already 65001. However, utF-8 Chinese characters are still garbled.** The current solution is to turn on utf-8 in the language set by the system. This does work, but some old applications may not support utf8, so there will be some problems.
Author
Owner

@eryksun commented on GitHub (Dec 22, 2021):

The console API doesn't support reading input as UTF-8, so it's a half-baked implementation. It only supports UTF-8 output, and that's only implemented properly for buffered writes in recent versions of conhost.

Reading input as UTF-8 is limited to ASCII, which is still the case even with Windows 11 and Windows Terminal Preview 1.12.3472.0. For example, here's a low-level os.read() in Python with the console input code page set to CP_UTF8 (65001):

>>> s = os.read(0, 10)
こんにちわ
>>> s
b'\x00\x00\x00\x00\x00\r\n'

Non-ASCII characters are replaced by null characters because the console's WideCharToMultiByte() call fails for each non-ASCII character. The call fails because the console doesn't allocate enough space for the 2-4 byte UTF-8 sequence.

@eryksun commented on GitHub (Dec 22, 2021): The console API doesn't support reading input as UTF-8, so it's a half-baked implementation. It only supports UTF-8 output, and that's only implemented properly for buffered writes in recent versions of conhost. Reading input as UTF-8 is limited to ASCII, which is still the case even with Windows 11 and Windows Terminal Preview 1.12.3472.0. For example, here's a low-level `os.read()` in Python with the console input code page set to `CP_UTF8` (65001): ```python >>> s = os.read(0, 10) こんにちわ >>> s b'\x00\x00\x00\x00\x00\r\n' ``` Non-ASCII characters are replaced by null characters because the console's `WideCharToMultiByte()` call fails for each non-ASCII character. The call fails because the console doesn't allocate enough space for the 2-4 byte UTF-8 sequence.
Author
Owner

@zadjii-msft commented on GitHub (Jan 3, 2022):

But powshell uses CHCP65001 to no effect, even though the actual CHCP output code is already 65001. However, utF-8 Chinese characters are still garbled.

This sounds like an issue with either PowerShell itself, or PSReadline, which should be filed over at https://github.com/powershell/powershell or https://github.com/powershell/psreadline. I'd suspect that updating to the latest version of both of those might just automatically fix this for you, I don't think PowerShell 5& PSReadline 2 (which ships with Windows) supported utf-8 input.

@zadjii-msft commented on GitHub (Jan 3, 2022): > **But powshell uses CHCP65001 to no effect, even though the actual CHCP output code is already 65001. However, utF-8 Chinese characters are still garbled.** This sounds like an issue with either PowerShell itself, or PSReadline, which should be filed over at https://github.com/powershell/powershell or https://github.com/powershell/psreadline. I'd suspect that updating to the latest version of both of those might just automatically fix this for you, I don't think PowerShell 5& PSReadline 2 (which ships with Windows) supported utf-8 input.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16150