You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HKCU\Console\CodePage ... does it do anything? #11591
Microsoft Windows 10 Pro for Workstations
10.0.19043.1288 (2009, 21H1)
I thought that HKCU\Console\CodePage set the default output code page for consoles (and I'm pretty sure that, at least once upon a time, it did). But it does not now. Although I have
hkcu\console
CodePage : REG_DWORD : 1252
all console apps which don't have another specification start with CP 437 (CP_OEMCP).
Shouldn't HKCU\Console\CodePage be setting the default?
And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437.
I just happened to be looking at this area of the code recently, so I have a general idea of how it works, and this looks like a bug to me. The place that the settings are initialized at startup is in the SetUpConsole function. You can see the relevant bit here:
// If we weren't started from a link, this will already be set.
// If LoadLinkInfo couldn't find anything, it will remove the flag so we can dig in the registry.
if (!(settings.IsStartupTitleIsLinkNameSet()))
{
reg.LoadFromRegistry(Title);
}
Note that it loads the setting from the default registry area first, then potentially overrides that with settings in the shortcut link, and if there was no shortcut link, it'll look again in the registry for settings specific to the current executable.
The problem, though, is that the SystemConfigurationProvider::GetSettingsFromLink method always resets the codepage to the OEM value, regardless of whether a shortcut link is even involved, so any value read from the default registry area is guaranteed to be reset. See here:
I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added. It's possible there's a legitimate reason for it.
And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437.
This seems to be by design. When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry. See here:
I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added.
If I recall correctly, the default "CodePage" setting was ignored in Windows 7. It definitely worked in Windows 2000, which I think was the first version of Windows that supported it. I verified this in Windows 2000 running in a VM.
When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry.
A pair of functions could be added to the API to get and set the classic console settings that are applicable in the pseudoconsole context, such as "CodePage" and "NumberOfHistoryBuffers". For example: GetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG) and SetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG). The "Settings" tab in Windows Terminal could have a page to modify the default pseudoconsole settings (not the defaults in the registry), which each profile would be able to override.
If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in #10408 (comment).
If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in #10408 (comment).
I'd be happy with setting it for all profiles. If I read you correctly, James Holderness (@j4james), that's not currently possible. The user should have some say ... yes/no?
Well the user does have some say. They can change the codepage with chcp. And if you're in a WSL shell you can at least change to something similar to 1252 with with echo -e '\e%@', and change back to UTF-8 with echo -e '\e%G'.
But Windows Terminal doesn't currently have any control over that (as far as I'm aware), because it's all handled in conhost. What gets passed to conpty (which is what Windows Terminal sees), is a simple stream of UTF-8 after everything has already been translated.
But if this is something you need to control from within Windows Terminal itself, I'd suggest upvoting #10870, which I believe is requesting the same thing. If you have a compelling use case for it, maybe explain what that is in a comment.
When I started this thread, I was thinking Windows should be honoring the default code page setting. The user should have some across-the-board control in consoles and in WT. I upvoted #10870 but didn't leave a use case. Today's compelling reason is that I prefer the first (below) to the second. :-)
v:\> chcp 1252 & type V:\wmips.btm | findstr ZZZ
Active code page: 1252
:: rewrite YYYYMMDDHHMMSS.mmmmmm±ZZZ
v:\> chcp 437 & type V:\wmips.btm | findstr ZZZ
Active code page: 437
:: rewrite YYYYMMDDHHMMSS.mmmmmm▒ZZZ
You know, I thought our plan of record was to actually kinda go in the opposite direction, and have conpty force itself into utf-8 mode by default - #1802. Of course, we never really achieved consensus on that one, and I don't think any of us thought it was a terribly high-priority issue.
Thanks for filing. We think the right solution to this is going to be allow the user to set the codepage in a compatibility page of the settings UI. This work spans several issues: #10870, #9174, #15678, and #1802. So we're going to mark this as a /dup of #1802, even though it's not necessarily the perfect solution to this question, but we'll use it to do the right thing.
microsoft-github-policy-service commented on Aug 9, 2023
Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Activity
j4james commentedon Oct 24, 2021
I just happened to be looking at this area of the code recently, so I have a general idea of how it works, and this looks like a bug to me. The place that the settings are initialized at startup is in the
SetUpConsolefunction. You can see the relevant bit here:terminal/src/host/srvinit.cpp
Lines 174 to 190 in 284257a
Note that it loads the setting from the default registry area first, then potentially overrides that with settings in the shortcut link, and if there was no shortcut link, it'll look again in the registry for settings specific to the current executable.
The problem, though, is that the
SystemConfigurationProvider::GetSettingsFromLinkmethod always resets the codepage to the OEM value, regardless of whether a shortcut link is even involved, so any value read from the default registry area is guaranteed to be reset. See here:terminal/src/interactivity/win32/SystemConfigurationProvider.cpp
Lines 58 to 70 in fb597ed
I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added. It's possible there's a legitimate reason for it.
j4james commentedon Oct 24, 2021
This seems to be by design. When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry. See here:
terminal/src/host/srvinit.cpp
Lines 165 to 172 in 284257a
eryksun commentedon Oct 24, 2021
If I recall correctly, the default "CodePage" setting was ignored in Windows 7. It definitely worked in Windows 2000, which I think was the first version of Windows that supported it. I verified this in Windows 2000 running in a VM.
A pair of functions could be added to the API to get and set the classic console settings that are applicable in the pseudoconsole context, such as "CodePage" and "NumberOfHistoryBuffers". For example:
GetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG)andSetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG). The "Settings" tab in Windows Terminal could have a page to modify the default pseudoconsole settings (not the defaults in the registry), which each profile would be able to override.j4james commentedon Oct 24, 2021
If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in #10408 (comment).
vefatica commentedon Oct 24, 2021
I'd be happy with setting it for all profiles. If I read you correctly, James Holderness (@j4james), that's not currently possible. The user should have some say ... yes/no?
j4james commentedon Oct 24, 2021
Well the user does have some say. They can change the codepage with
chcp. And if you're in a WSL shell you can at least change to something similar to 1252 with withecho -e '\e%@', and change back to UTF-8 withecho -e '\e%G'.But Windows Terminal doesn't currently have any control over that (as far as I'm aware), because it's all handled in conhost. What gets passed to conpty (which is what Windows Terminal sees), is a simple stream of UTF-8 after everything has already been translated.
But if this is something you need to control from within Windows Terminal itself, I'd suggest upvoting #10870, which I believe is requesting the same thing. If you have a compelling use case for it, maybe explain what that is in a comment.
vefatica commentedon Oct 24, 2021
When I started this thread, I was thinking Windows should be honoring the default code page setting. The user should have some across-the-board control in consoles and in WT. I upvoted #10870 but didn't leave a use case. Today's compelling reason is that I prefer the first (below) to the second. :-)
vefatica commentedon Oct 24, 2021
The pasted text in my last post looks peculiar in MSEGDE. It should look like this.
j4james commentedon Oct 24, 2021
If you're using a cmd shell, you could just change the command line in your Windows Terminal profile to something like this:
cmd.exe /k chcp 1252vefatica commentedon Oct 24, 2021
... or use CMD's AutoRun file. I don't use CMD often. For any command interpreter, there are specific work-arounds.
zadjii-msft commentedon Nov 3, 2021
You know, I thought our plan of record was to actually kinda go in the opposite direction, and have conpty force itself into utf-8 mode by default - #1802. Of course, we never really achieved consensus on that one, and I don't think any of us thought it was a terribly high-priority issue.
carlos-zamora commentedon Aug 9, 2023
Thanks for filing. We think the right solution to this is going to be allow the user to set the codepage in a compatibility page of the settings UI. This work spans several issues: #10870, #9174, #15678, and #1802. So we're going to mark this as a /dup of #1802, even though it's not necessarily the perfect solution to this question, but we'll use it to do the right thing.
microsoft-github-policy-service commentedon Aug 9, 2023
Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!