Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of multi-space characters #85

Open
jwlodek opened this issue Jan 21, 2021 · 2 comments
Open

Improve handling of multi-space characters #85

jwlodek opened this issue Jan 21, 2021 · 2 comments
Labels
Bug Something isn't working Help wanted Extra attention is needed Renderer Issue has to do with Renderer
Milestone

Comments

@jwlodek
Copy link
Owner

jwlodek commented Jan 21, 2021

Describe the bug
When using certain multi-space unicode characters in certain terminal emulators, character lengths are incorrectly reported when using the len function, which causes some incorrect rendering of terminal elements.

To Reproduce
Steps to reproduce the behavior:

  1. Write py_cui interface that use the FOLDER and FILE unicode icons
  2. Run in windows terminal
  3. See invalid display of widgets

Expected behavior
Rendering multi space unicode characters should not result in artefacting

Screenshots
Will update later.

Environment:

  • OS: Windows 10
  • Terminal: windows-terminal
  • Version: v0.1.3 (pre-release)
@jwlodek jwlodek added Bug Something isn't working Help wanted Extra attention is needed Renderer Issue has to do with Renderer labels Jan 21, 2021
@jwlodek jwlodek added this to the v0.2.0 milestone Jan 21, 2021
@jwlodek jwlodek mentioned this issue Jan 21, 2021
3 tasks
@jupiterbjy
Copy link
Contributor

I encountered this when first started making audio player with CJK letters.

for i.e. normally 2-width characters such as all CJK letters permanently breaks alignments, even in Linux:

image

This is just as same as 2-width Unicode characters.


For that reason, I was not able to rely on built-in functions, as it turned out like this. I used a module wcwidth to fix that. Full implementation code if interested.

Intenally, there is no way of knowing how wide a character is in python, so what wcwidth module doing is, manually create a gigantic table with all known Unicode character's width. Since Python3 internally process all strings in utf8 this works.

However, importing such model is huge breaking change. Therefore, I suggest either creating PR for Curses, or make this module optional. If wcwidth is available, use new drawing logic. Else use original drawing logic.

Will make a new PR if you approve this "Optional import" way, let me know!

@jwlodek
Copy link
Owner Author

jwlodek commented Feb 5, 2021

I'll take a look at your code. I'd rather avoid any major breaking changes to avoid having to maintain too many variations of things like the renderer. I have some ideas of how to handle this I'll probably get around to it when I have some more time away from work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Help wanted Extra attention is needed Renderer Issue has to do with Renderer
Projects
None yet
Development

No branches or pull requests

2 participants