Closed ralphptorres closed 1 year ago
That is a nice idea and also should be straight forward to implement in the text
file as a new property which preprocesses the text. If you like you could try to raise a PR.
Not a prolific coder but will try :)
I realised that it is not as straight forward as I made it seem, since caution has to be applied for multibyte unicode sequences. Simply truncating the char*
is thus not enough, making this a bit subtle so I decided to implement it. The new property is called max_chars
and take a positive integer. The strings are truncated by a horizontal ellipsis symbol (i.e.: …).
Tested, it works. The only issue I'm aware of is char counting: max_chars
means max bytes. So one multi-byte char (e.g. emoji, cjk, etc.) takes up a few from the count as expected.
But since truncation got implemented, we can already close this issue. Thanks for the work!
The only issue I'm aware of is char counting:
max_chars
means max bytes. So one multi-byte char (e.g. emoji, cjk, etc.) takes up a few from the count as expected.
I have implemented it such that multi-byte chars are only counted as one char, so max_chars=4
should allow you to print 4 unicode characters e.g. 4 emojis or 4 regular letters. So this should not be an issue?
I retested and you’re right, that’s the case. Sorry for misreporting. I used the emoji sequence ones (e.g. country flags) rather than the plain ones. 😅
I am aware of delegating the string truncation to the scripts used in bar items, say with
sed
orcut
as in here. I use this method myself (either withcut
or shell parameter expansion). But I thought that since icons and labels are just strings anyway, it would be nice to have the ability to set the max length via a command option. That way, we can usesketchybar --default
to enable truncation globally without having to do them manually in each item where it's necessary. Not only it will enable truncation for bar items that do not use scripts, it will also reduce computational cost compared to when usingsed
orcut
(though I know these two aren't really costly).