About effective text length measuring for PowerShell #2083
Replies: 3 comments 5 replies
-
Up for a good suggestion. It's a tricky thing and requires skills/knowledge I don't possess yet. Might need to have a read about the topic. |
Beta Was this translation helpful? Give feedback.
-
Ah oh, sorry that I forgot the prerequisite "in PowerShell". As we know, zsh has a native right prompt support ( |
Beta Was this translation helpful? Give feedback.
-
@JanDeDobbeleer Now I come back to this topic again. I just found that go-runewidth handles most of the wide characters (especially CJK) properly. Although this is not an absolute perfect solution (e.g., the width of a flag emoji cannot be measured correctly for the time being), it does much better than |
Beta Was this translation helpful? Give feedback.
-
The current
(*color.Ansi).MeasureText
method usesutf8.RuneCountInString
to measure the effective text length, it calculates in unit of Unicode characters instead of cells on terminal screen, which will cause tooltips or any right-aligned segments in PowerShell to be displayed incorrectly (typically a line break) when the text includes wide characters (e.g., CJK characters) or something like backspaces (mostly act as part of a trick to tweak the rendering results). See the screenshot below:Should we find a better way to handle this?
Beta Was this translation helpful? Give feedback.
All reactions