-
Notifications
You must be signed in to change notification settings - Fork 650
support variation selectors, ZWJ sequences and surrogate pairs in length calculation #2082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
patriksvensson
merged 3 commits into
spectreconsole:main
from
fabsenet:1847-unicode-widechar-table
Apr 16, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...tre.Console.Tests/Expectations/Widgets/Table/Render_Wide_Emoji_Hearts.Output.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ┌──────────┬────────┬──────────────────────┐ | ||
| │ hearts │ length │ LengthInTextElements │ | ||
| ├──────────┼────────┼──────────────────────┤ | ||
| │ wide ❤️ │ 2 │ 1 │ | ||
| │ normal ♥ │ 1 │ 1 │ | ||
| └──────────┴────────┴──────────────────────┘ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Spectre.Console.Tests.Unit; | ||
|
|
||
| public sealed class CellTests | ||
| { | ||
| [Theory] | ||
| [InlineData("A", 1)] // ASCII | ||
| [InlineData("中", 2)] // CJK wide | ||
| [InlineData("♥", 1)] // U+2665 text heart, no variation selector | ||
| [InlineData("❤️", 2)] // U+2764 + U+FE0F emoji variation selector | ||
| [InlineData("👨👩👧", 2)] // ZWJ family sequence | ||
| [InlineData("❤️🔥", 2)] // U+2764 + FE0F + ZWJ + U+1F525 (heart on fire) | ||
| [InlineData("🇩🇪", 2)] // Regional Indicator pair (flag) | ||
| [InlineData("", 0)] // empty string | ||
| [InlineData("Hello World", 11)] | ||
| public void GetCellLength_Returns_Correct_Display_Width(string text, int expectedWidth) | ||
| { | ||
| Cell.GetCellLength(text).ShouldBe(expectedWidth); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this obviosly is now not fixed for .net standard 2.0. UnicodeCalculator.GetWidth(string) is not available for .net standard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are completely correct. I look forward to drop netstandard2.0 at some point (around the 2.0 release of Spectre.Console). For now, I'm OK with having two different implementations (and potentially erroneous rendering on .NET Framework). What do you think?