Skip to content

Conversation

@HarryLHW
Copy link
Contributor

@HarryLHWHarryLHW commented Feb 18, 2025

foriinrange(start, len(line)):
ifwidth<=0:
returni, line[start:i]
width-=2ifeast_asian_width(line[i]) in_WIDE_CHAR_SPECIFIERSelse1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this correctly handle zero-width characters? e.g. the '\u0301' from 'cafe\u0301'

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.
However, _display_width() does not correctly handle zero-width characters for carets positions either.

>>> café = 1/0 Traceback (most recent call last): File "<python-input-0>", line 1, in <module> café =1/0~^~ZeroDivisionError: division by zero >>> 

They can be fixed in the same way. I wonder how I can find all the zero-width characters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are many zero-width characters: https://wcwidth.readthedocs.io/en/latest/specs.html#width-of-0

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how wcwidth implements wcswidth() and wcwidth(): https://wcwidth.readthedocs.io/en/latest/_modules/wcwidth/wcwidth.html#wcswidth
Maybe it is too complicated for our traceback? Could we have a simple way that can handle most of the cases?

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@HarryLHW@grayjk