[英]Visual Studio Code distorts ANSI characters
I have problems with Swedish national characters when using Rust in Visual Studio Code in Windows 11. It can be shown with the following program:我在 Windows 11 中的 Visual Studio Code 中使用 Rust 时遇到瑞典国家字符问题。可以用以下程序显示:
fn main() {
let abc = " ååå
ööö
äää";
println!("<---{}--->", abc);
}
When the program is run from the command line using "cargo run", the output is as follows:使用“cargo run”从命令行运行程序时,output 如下所示:
<--- ååå
ööö
äää--->
Strangely, spaces are added at the beginning of lines 2 and 3. However, when the program is run in Visual Studio Code, the Swedish characters get distorted.奇怪的是,第 2 行和第 3 行的开头添加了空格。但是,当程序在 Visual Studio Code 中运行时,瑞典语字符会失真。
<--- ååå
├╢├╢├╢
äää--->
How can I solve it?我该如何解决? I work with text processing and this is a major problem.
我从事文本处理工作,这是一个主要问题。
EDIT : Since the problem doesn't appear on many systems, I add the technical data: Windows 11 Pro Version 10.0.22621 Build 22621;编辑:由于这个问题在很多系统上都没有出现,我添加了技术数据:Windows 11 Pro Version 10.0.22621 Build 22621; Visual Studio Code Version: 1.73.1 (user setup) Date: 2022-11-09 Chromium: 102.0.5005.167 Node.js: 16.14.2 Sandboxed: No.
Visual Studio Code 版本:1.73.1(用户设置)日期:2022-11-09 Chromium:102.0.5005.167 Node.js:16.14.2 沙盒:No.
EDIT 2 : The problem is solved by adding the following:编辑 2 :通过添加以下内容解决问题:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"/c",
"chcp.com 65001"
]
},
},
as the first parameter in settings.json
and saving the changes.作为
settings.json
中的第一个参数并保存更改。
- This answer is Windows specific. - 这个答案是 Windows 具体的。 -
-
INFO: This answer describes you how can change your VSCode settings to force UTF-8 in your console.信息:此答案向您描述了如何更改您的 VSCode 设置以在您的控制台中强制使用 UTF-8。 An alternative to this answer would be to force UTF-8 system-wide, as described here: Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)
此答案的替代方法是在系统范围内强制使用 UTF-8,如下所述: 在命令提示符中使用 UTF-8 编码 (CHCP 65001) / Windows Powershell (Windows 10)
It seems that sometimes the Windows shell doesn't use the correct UTF-8 code page.似乎有时 Windows shell 没有使用正确的 UTF-8 代码页。
You can tell VSCode to force a codepage in its shell using the following settings.您可以使用以下设置告诉 VSCode 在其 shell 中强制使用代码页。
Settings
page (Shortkey: Ctrl+,
)Settings
页面(快捷键: Ctrl+,
) "terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"/c",
"chcp.com 65001"
]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"chcp 65001"
],
"icon": "terminal-cmd"
},
},
This will force the UTF-8
code page.这将强制使用
UTF-8
代码页。
If it worked, opening a new shell should display Active code page: 65001
.如果有效,打开一个新的 shell 应该显示
Active code page: 65001
。
Source: https://github.com/microsoft/vscode/issues/19837来源: https://github.com/microsoft/vscode/issues/19837
Previous, deprecated settings:以前的弃用设置:
"terminal.integrated.shellArgs.windows": ["/K", "chcp 65001"],
"terminal.integrated.shellArgs.windows": ["-NoExit", "/c", "chcp.com 65001"],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.