Skip to content

feat: unicode display width support#502

Open
Wybxc wants to merge 2 commits intoanmol098:masterfrom
Wybxc:master
Open

feat: unicode display width support#502
Wybxc wants to merge 2 commits intoanmol098:masterfrom
Wybxc:master

Conversation

@Wybxc
Copy link
Copy Markdown
Contributor

@Wybxc Wybxc commented May 1, 2024

Compute unicode display width instead of string length.

Before:

🐱‍💻 Projects: 
计算机网络                    1 hr 58 mins        ████████░░░░░░░░░░░░░░░░░   32.72 % 
alphartc                 1 hr 51 mins        ████████░░░░░░░░░░░░░░░░░   30.67 % 
rust_learning_group_ans  1 hr 45 mins        ███████░░░░░░░░░░░░░░░░░░   29.21 % 
erg-prover               18 mins             █░░░░░░░░░░░░░░░░░░░░░░░░   05.12 % 
typst                    8 mins              █░░░░░░░░░░░░░░░░░░░░░░░░   02.28 % 

After:

🐱‍💻 Projects: 
计算机网络               1 hr 58 mins        ████████░░░░░░░░░░░░░░░░░   32.72 % 
alphartc                 1 hr 51 mins        ████████░░░░░░░░░░░░░░░░░   30.67 % 
rust_learning_group_ans  1 hr 45 mins        ███████░░░░░░░░░░░░░░░░░░   29.21 % 
erg-prover               18 mins             █░░░░░░░░░░░░░░░░░░░░░░░░   05.12 % 
typst                    8 mins              █░░░░░░░░░░░░░░░░░░░░░░░░   02.28 % 

Preview:

image

pseusys
pseusys previously approved these changes May 2, 2024
@Wybxc
Copy link
Copy Markdown
Contributor Author

Wybxc commented Sep 18, 2024

It appears that a previous CI failure is blocking this pull request. I will push a new commit to trigger the CI again and work on resolving the issue.

Copilot AI review requested due to automatic review settings January 14, 2026 13:05
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file python Pull requests that update Python code labels Jan 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

:param length: The length to pad the string to.
:returns: The padded or truncated string.
"""
width = wcswidth(string)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The wcswidth function can return -1 when the string contains non-printable characters (e.g., control characters). This will cause incorrect behavior in the padding logic. Consider adding a check to handle this case, for example by falling back to using len(string) when wcswidth returns -1.

Suggested change
width = wcswidth(string)
width = wcswidth(string)
if width < 0:
# Fallback for strings with non-printable characters where wcswidth returns -1.
width = len(string)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants