String len() is used as width
See original GitHub issueDescription of the problem
Looking at the code I see many lines where the len()
of a string is used for the (terminal-)width of this string. But there are codepoints with width 0 and 2. For example “o” with an arrow above: o⃗ (U+006F U+20D7). The U+20D7 arrow has width 0. Or 😼 (U+1f63c): this codepoint has width 2. If one enters or uses such codepoints the whole layout is “out of sync”.
Example
Here is an example with demo.py
and the form widgets: Before:
and after:
Question
Are there any plans to support wcwidth
?
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:16 (14 by maintainers)
Top Results From Across the Web
Calculating String length and width – Fun with Unicode
len() The first function you'll probably come across is String. len() / str/len() , or length of string. Given the string "abc" it...
Read more >Calculate the display width of a string in Java - Stack Overflow
stringWidth to find the width for the specified string. For example, if you have a Graphics variable called g , you'd use: int...
Read more ><length> - CSS: Cascading Style Sheets - MDN Web Docs
Lengths can be used in numerous CSS properties, such as width, height, margin, padding, border-width, font-size, and text-shadow.
Read more >Compute the length/width — str_length • stringr
str_width() returns how much space the string will occupy when printed in a fixed width font (i.e. when printed in the console).
Read more >Using the len() Function in Python
The function returns the number of rows in the array when you pass this two-dimensional array as an argument in len() . To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Vim is (in this context) not suitable (as width test, etc.) because for an editor there are other requirements than for a terminal emulator. Fun fact: Gtk-Vim can render some(!) combining characters correctly because of this patch from me 😃
Until the terminal persons reach some “consensus” how to handle ZWJ and Var-Selectors etc. and adapt their terminal emulators, I think your “size of char test” is an acceptable approximation (and fast because no ECG-segmentation is performed). [The other option “to program for all the different terminal emulator behaviours and/or place the cursor explicitly after every ZWJ and Var-Selectors” is toooo much work.]
So let’s close, or?
I am also experiencing this problem with ANSI color codes. I believe the library is considering color sequences as part of terminal length. Maybe this can be helpful for fixing this issue, it is a fix that another project used for this very same problem: Tabulate source code