ansi: document that StringWidth treats tabs as zero width - #864
Open
c-tonneslan wants to merge 1 commit into
Open
ansi: document that StringWidth treats tabs as zero width#864c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
This trips people up: ansi.StringWidth("\t") returns 0 because tab is a
C0 control character whose display width depends entirely on terminal
tabstop settings, and the package can't know what those are. The same
goes for the rest of the C0 range.
Maintainer signed off on documenting this in charmbracelet#644 and suggested showing
how to pre-expand tabs with strings.ReplaceAll, so do that on
StringWidth and point StringWidthWc at the same caveat.
Closes charmbracelet#644
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #644.
ansi.StringWidth(\"\t\")returns 0 because tab is a C0 control character whose display width depends on terminal tabstop settings the package can't know about. That's intentional but unexpected if you're feeding raw user input through it. @aymanbagabas confirmed in the issue thread that this is by design and suggested a doc note with astrings.ReplaceAllexample, so that's what this does. Same caveat noted onStringWidthWc.