Add configurable ambiguous-width policy (narrow/wide)#19864
Add configurable ambiguous-width policy (narrow/wide)#19864DHowett merged 6 commits intomicrosoft:mainfrom
Conversation
Reason:\n- Address ambiguous-width rendering requests discussed in microsoft#153 and microsoft#370 without introducing a locale-based default policy.\n\nScope:\n- Add compatibility.ambiguousWidth as narrow|wide and wire it through settings model/schema/UI.\n- Propagate the selected mode through Terminal -> ConPTY -> winconpty -> conhost argument paths.\n- Replace fixed ambiguous width handling in CodepointWidthDetector with policy-based resolution and keep related width paths consistent.\n- Extend regression coverage for ambiguous symbols, DEC special-character alignment, fallback lifecycle stability, and emoji/VS16-adjacent behavior.\n\nBreaking changes:\n- None. Default behavior remains narrow.
|
@microsoft-github-policy-service agree |
src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h
Outdated
Show resolved
Hide resolved
Reason: review pointed out unnecessary newline code changes in PR microsoft#19864. Impact: keep logical changes intact while normalizing edited files to repository line endings. Breaking change: none.
|
Fonts may have an influence. Perhaps this is the reason why you are facing overlapping glyphs, which I was not even able to reproduce (FWIW, Cascadia Mono in my case). Besides of that, my observation is that PowerShell 5.1 in particular bahaves weirdly. As your screenshots seem to demonstrate how it looks like in PS 5.1 only, I'm wondering what this setting does to the experience in other shells? I tried to have the cursor visible in the screen captures, just to show that the "A" is written adjacent to the last arrow, no matter if the cursor has been already advanced to an even farther position in PS 5.1. Other shells (CMD, WSL) do not misplace the cursor. The behavior of PS 5.1 can also be reproduced in a conhost window though. To be clear, I'm not questioning this new setting. And I also don't know how much my observations interact with specifics of CJK scripts in general. However, it might be more reasonable to make it a profile setting
What do you think? |
… policy Reason: when --textMeasurement is omitted, conpty init could leave width recognition mode implicit, causing ambiguity-width related drift. Scope: always initialize VtIo text measurement to graphemes by default and add regression tests for default/explicit textMeasurement+ambiguousWidth propagation. Breaking changes: none.
82d9bad to
4a09610
Compare
|
@german-one In real CJK usage, some users choose fonts that render East Asian Ambiguous characters as width 2 for readability. This PR provides wide as a relief option for that kind of environment. At the same time, the default remains narrow, so compatibility-first behavior is preserved by default (wide is explicit opt-in). We also recognize the side effect that cursor/Backspace behavior can diverge in readline-based environments. That behavior depends on how the receiving application computes character width. We are not hiding this; it is now explicitly documented as a known limitation in both the HelpText and the PR description. So the intent of this PR is to provide an explicit option for readability-focused cases, while clearly disclosing the tradeoff. I also attached reference screenshots (HelpText reinforcement in Settings, plus the known readline-side behavior).
|
I think it would be better to add a third option (auto?) to automatically determine the width based on the current font (similar to Conhost's behavior)? ofc I admit that implementing this might involve some work. |
We are absolutely not going to do that. That was one of the biggest mistakes the original Windows Console made, and it means that standards-conforming applications cannot accurately predict how big something is going to be without knowing--and manually parsing--the font. Accessing the font is impossible over a remote connection (for example, and among other reasons.) If you want that behavior, you can stick with the original Windows Console. 🙂 |
|
Thanks everyone for the feedback and discussion. I agree that an automatic/font-dependent mode is probably not the right direction, since it can make character width less predictable for applications (especially over remote connections). What this PR is trying to do is more limited: keep today’s default behavior as-is, while offering an explicit opt-in for users/environments (including some CJK setups) that prefer ambiguous characters to be treated as wide. So the intent here is explicit selection with clear tradeoffs ( |
|
FYI, there is a mode supported by some terminals to switch between narrow and wide for ambiguous width characters. That at least allows applications to make the choice to opt in if they're prepared to handle the non-standard widths. That said, you may still want the option to allow users to force the mode on, and I'm in agreement with @german-one that it should probably be a per-profile setting. I understand that there may be architectural reasons why this isn't feasible. ETA: The mode number I'm referring to is |
There was a problem hiding this comment.
@unagi I have finished reviewing your PR. First off, thank you for submitting this - you did a great job creating this! The code was in all the right places and I did not have to add anything. (I did remove some things though.)
I have pushed a commit that simplifies your logic a bit. For instance, instead of passing --ambiguousWidth narrow/wide it just passes a boolean flag --ambiguousIsWide. I also rewrote the settings description slightly to better fit the existing tone (personal opinion). All of that are just minor issues though.
But I also have one actual critique: Your PR was written by AI, and that's absolutely fine. However, we expect contributors to read & understand their submission too. There were some spots where I'm quite certain that you didn't review it yourself yet. For instance, the unit tests asserted on the width of U+2666 ♦ being ambiguous width. That character is documented as "neutral" width which means it's always narrow. Another example is the rewrite of the CodepointWidthDetector which broke the TextMeasurementMode::Console mode. The good news is that I fixed these instances and the PR is a lot smaller now.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| <comment>A label for a drop down selector, referring to the East Asian Ambiguous Width Unicode specification.</comment> | ||
| </data> | ||
| <data name="Globals_AmbiguousWidth.HelpText" xml:space="preserve"> | ||
| <value>Sets the width used for East Asian Ambiguous characters. "Narrow" (default) prioritizes compatibility, while "Wide" prioritizes readability with many CJK fonts. In "Wide" mode, some applications may not work correctly and cause erratic cursor movement. Changing this setting requires a restart of Windows Terminal and it only applies to applications launched from within it.</value> |
There was a problem hiding this comment.
Is "East Asian" the correct term of art here?
There was a problem hiding this comment.
I think it's appropriate, because the spec is called such.
src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
Outdated
Show resolved
Hide resolved
Co-authored-by: Dustin L. Howett <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |










This PR introduces
compatibility.ambiguousWidthas a globalcompatibility setting (
narrowdefault,wideoptional).The default remains
narrow.Why global-only in this PR:
CodepointWidthDetectorsingleton).
architectural changes and is intentionally deferred to a follow-up
design/PR.
What this PR guarantees:
ambiguous-width policy (rendering path + ConPTY/host propagation).
Known limitation:
may still compute character widths independently.
visual cell width even when terminal-side policy is consistent.
This is a compatibility/readability trade-off feature:
narrow: prioritize cross-application compatibility.wide: prioritize readability with many CJK fonts.Closes #153
Closes #370
Refs #2928
Refs #2049, #2066, #2375, #900, #5910, #5914
Co-authored-by: Leonard Hecker [email protected]