Add a startup code page setting for terminal profiles #20817
<!-- AzurePipelinesStatusComment -->
<samp>
Azure Pipelines:<br>
There may be pipelines that require an authorized user to comment /azp run to run.<br>
</samp>
check-spelling / Unrecognized Spelling
[CPINFOEXW](#security-tab) is not a recognized word
@check-spelling-bot Report
🔴 Please review
See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.
Unrecognized words (1)
CPINFOEXW
<details><summary>These words are not needed and should be removed
</summary>ADDREF CLAUDE yizz
</details><p></p>
<details><summary>To accept these unrecognized words as correct and remove the previously acknowledged and now absent words,
you could run the following commands</summary>
... in a clone of the git@github.com:s911415/windows-terminal.git repository
on the dev/s911415/profile-codepage branch ([ℹ️ how do I use this?](
https://docs.check-spelling.dev/Accepting-Suggestions)):
`` sh
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/39044528464/attempts/1' &&
git commit -m 'Update check-spelling metadata'
json</details>
<details><summary>Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary</summary>
This includes both **expected items** (2030) from .github/actions/spelling/expect/alphabet.txt .github/actions/spelling/expect/expect.txt .github/actions/spelling/expect/web.txt and **unrecognized words** (1)
Dictionary | Entries | Covers | Uniquely
-|-|-|-
[cspell:cpp/src/lang-keywords.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/cpp/src/lang-keywords.txt)|44|3|3|
[cspell:csharp/csharp.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/csharp/csharp.txt)|32|2|2|
[cspell:cpp/src/compiler-clang-attributes.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/cpp/src/compiler-clang-attributes.txt)|46|2|2|
[cspell:aws/aws.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/aws/aws.txt)|218|2|2|
[cspell:python/src/python/python.txt](https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20230509/dictionaries/python/src/python/python.txt)|392|2|2|
Consider adding to the `extra_dictionaries` array (in the `.github/actions/spelling/config.json` file):
"cspell:cpp/src/lang-keywords.txt",
"cspell:csharp/csharp.txt",
"cspell:cpp/src/compiler-clang-attributes.txt",
"cspell:aws/aws.txt",
"cspell:python/src/python/python.txt",
To stop checking additional dictionaries, put (in the `.github/actions/spelling/config.json` file):
json"check_extra_dictionaries": []
`
</details>
<!-- See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples%3A-advice --> <!-- markdownlint-disable MD033 MD041 -->
<details>
<summary>
:pencil2: Contributor please read this
</summary>
By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
... misspelled, then please correct them instead of using the command.
... names, please add them to
.github/actions/spelling/allow/names.txt.
... APIs, you can add them to a file in .github/actions/spelling/allow/.
... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.See the
README.md in each directory for more information.:microscope: You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. :wink:
<details><summary>If the flagged items are :exploding_head: false positives</summary>
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt file matching the containing file. File paths are Perl 5 Regular Expressions - you can [test](
https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your files.
^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude [README.md](
../tree/HEAD/README.md) (on whichever branch you're using).well-formed pattern. If you can write a [pattern](
https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns
) that would match it,
try adding it to the
patterns.txt` file. Patterns are Perl 5 Regular Expressions - you can [test](
https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
</details>
</details>
@microsoft-github-policy-service agree
I wonder if this one should wait for inproc-ConPTY where this can be achieved trivially. It _is_ somewhat rare for a person to want to change the default CP used by conhost after all.
lhecker
s911415
Summary of the Pull Request
Windows Terminal is a terminal host rather than a traditional console application, so the per-application settings under
HKCU\Consoledo not apply towt.exein the same way they apply to applications running inside a console. In addition, ConPTY sessions intentionally ignore console user settings, including the registryCodePagevalue.As a result, users cannot configure the initial code page of a Windows Terminal session through the Console registry. Running
chcpor a shell startup script is not equivalent because it occurs after the console and client process have already been initialized, and it is not a shell-independent profile setting.This change adds an opt-in, profile-level
codePagesetting and passes the resolved value to the bundled OpenConsole host before launching the client process.The setting is intentionally opt-in. This PR does not make code page 65001 the default because changing the startup code page of all existing profiles could break legacy applications that depend on an OEM or locale-specific code page. Users can enable UTF-8 through
profiles.defaultsor select another installed code page for an individual profile.When the setting is omitted, the existing console-host default is preserved.
References and Relevant Issues
Closes #15678
Detailed Description of the Pull Request / Additional comments
Settings model and precedence
Adds
codePageas an inheritable profile setting with the following precedence:1. Individual profile
2.
profiles.defaults3. Existing console-host default
The unset value is represented internally as
0. This preserves the existing host behavior rather than explicitly selecting a code page.The profile schema accepts integer code page identifiers. OpenConsole validates a nonzero value with the Windows Code Page APIs before applying it.
Settings UI
Adds a searchable Code Page picker to the Advanced profile settings page.
The picker:
EnumSystemCodePagesW.GetCPInfoExW.(Default)for Profile Defaults when unset.(Inherited)for an individual profile when unset.Selecting the first entry, using the AutoSuggestBox clear button, or using the reset button clears only the current profile layer.
ConPTY and OpenConsole initialization
For local terminal sessions, Windows Terminal places the resolved code page in the existing connection
ValueSet. The publicConptyConnection::CreateSettings()WinRT signature remains unchanged.An internal ConPTY creation path passes the requested value to the bundled
OpenConsole.exethrough:OpenConsole applies the code page before screen-buffer initialization and before launching the client process. Input and output DBCS metadata are initialized after selecting the startup code page.
The custom argument is never passed to the inbox
conhost.exefallback because that host does not support it. If a profile requests a code page while Windows Terminal must use the inbox host, the existing fallback behavior is preserved and Windows Terminal displays a warning that the requested code page could not be applied.Backward compatibility
Code page 65001 is not enabled by default.
Changing the default would alter every existing local profile and could break legacy applications that use code page-dependent console APIs or expect the current OEM or locale-specific code page.
Users who want UTF-8 for all profiles can configure:
An individual profile can override the shared default when it requires another installed code page.
Demo
<img width="800" height="449" alt="722e2af7-db7d-48fa-8020-04c789514d18" src="https://github.com/user-attachments/assets/85d3cdcc-242b-4a53-aecc-32eec30e4837" />
<img width="1112" height="626" alt="image" src="https://github.com/user-attachments/assets/5242d0f4-642c-4088-a63b-58eb7f2682b8" />
Validation Steps Performed
The complete change was reviewed and tested manually on Windows with an x64 Release build.
Manual validation covered:
(Default)when unset.(Inherited)when unset.profiles.defaultsprecedence.codePageis omitted.chcp.All tests added for this change passed in the x64 Release configuration:
ConsoleArgumentsTests::CodePageArgTestsInitTests::TestInitializeConsoleCodePageTerminalSettingsTests::CodePagePrecedenceCodePageUtilsTests::UnsetTextMatchesProfileLayerCodePageUtilsTests::FilterMatchesOnlyDisplayedTextCodePageUtilsTests::ClearRequiresEmptyUserInputCodePageUtilsTests::SingleResultCommitRequiresNoChosenSuggestionConPtyTests::CodePageTestsThe settings-model tests cover:
profiles.defaultsprecedence.The picker helper tests cover:
(Default)and(Inherited)selection.The ConPTY tests cover:
cmd.exe /d /c chcpand verifying that its output reports code page 65001.PR Checklist
- A paired MicrosoftDocs/terminal PR will be filed after initial review confirms the approach.