question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String len() is used as width

See original GitHub issue

Description 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: 20221122_210446 and after: 20221122_210526

Question

Are there any plans to support wcwidth?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
luchrcommented, Dec 7, 2022

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?

1reaction
zerowhybrcommented, Nov 25, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found