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

Token min and max width calculations wrong with non-ASCII characters #3074

Open
patrick96 opened this issue Jan 16, 2024 Discussed in #3069 · 0 comments
Open

Token min and max width calculations wrong with non-ASCII characters #3074

patrick96 opened this issue Jan 16, 2024 Discussed in #3069 · 0 comments

Comments

@patrick96
Copy link
Member

The calculation for padding and truncation of label tokens is inconsistent. For max-width it counts the number of unicode characters while for min-width it counts the number of bytes. This falls apart if the token text contains non-ASCII.

We should always use unicode codepoints for min and max-width

Discussed in #3069

Originally posted by nymver January 4, 2024
So I have a module that displays the artist and title of current playing song. I have specified tokens (minimum and maximum width) (label = %output:-45:45%). If there are no Cyrillic letters in the text, everything is fine, but if there are, for some reason the width of the label is reduced.

Module:

[module/running_string]
type = custom/script
exec = $HOME/.config/polybar/scripts/running_string
tail = true
format = <label>
label = %output:-45:45%

Screenshot_2024-01-04_02 42 18
Screenshot_2024-01-04_02 42 24

@patrick96 patrick96 added this to the 3.7.2 milestone Jan 16, 2024
patrick96 pushed a commit to patrick96/polybar that referenced this issue Feb 10, 2024
patrick96 added a commit that referenced this issue Feb 10, 2024
…3090)

* Changed bit count for label to use UTF8 standard

Fixes #3074

* label: Calculate length only once

The length calculation has to traverse the whole string

---------

Co-authored-by: nklloyd <nicholask.lloyd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant