Replies: 1 comment
|
I think it would be interesting to create a WcwidthExtensions class to fill in the remaining size discrepancies. But it would be advisable to create unit tests for these same graphemes that confirm they return a different size than the Wcwidth NuGet package, in case an update corrects these differences, and thus remove them from the code in the WcwidthExtensions class. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When text is rendered, the font may actual draw the grapheme outside the number of cells reported. For my file viewer app using Terminal.Gui I've addressed this in two ways.
First I have a function GetGraphemeToDisplay(string grapheme) which can translate the string into what should be actually displayed. This is specific to my app but could be a useful general function provided by Terminal.Gui perhaps.
///
/// Returns the display form of a grapheme.
/// Transforms raw graphemes into what should actually be displayed:
/// - control chars → control picture symbols (␀, ␊, etc.) when showControlPictures is true
/// - combining marks → dotted circle + mark (◌̀)
/// - flags → country code + 🏳
/// - keycaps → [X]
/// - wide-rendering scripts → char + trailing space
/// - zero-width/invisible → empty
/// - lone surrogates, unassigned, replacement char → replacement char or empty
/// - everything else → itself at measured width
///
public (string displayText, int cellWidth) GetGraphemeToDisplay(string grapheme, bool showControlPictures = false, bool showReplacementChar = false, bool showWhitespace = false)
This uses another function which reports the grapheme width in cell units. This is to address an issue that is seen in how the underlying grapheme width is reported, because what you see is that for East Asian scripts, the reported width is not really wide enough, so there is padding needed. This is based on Windows Terminal, and I'm not sure how well this maps across different platforms, fonts, etc. I just adjusted this manually looking at some examples but haven't done this completely. I wanted to discuss if it would be helpful to bring either of these over into Terminal.Gui.
All reactions