Closed Delta456 closed 4 years ago
I'm not sure what your question is. This package is not about character widths. Check out mattn/go-runewidth
for that.
If you have a specific question about the uniseg
package, let me know.
I am using uniseg
package and counting the len but it doesn't seem to work for me case I think it's the problem of uniseg
's len
function.
The uniseg
package gives you the number of characters in a string. If there is one Japanese or Chinese character, that's a length of 1. I don't even know what "half a character" would be.
Again, "width" is a different measure and it heavily depends on the context of where a character is drawn. For terminals, please see the other package I mentioned above. For graphical user interfaces, the width depends on the font you're using. But both are not the problem that uniseg
tries to solve.
If you still believe your issue is related to this package, please provide an example (code/screenshots) to help me understand it.
Sure, try this on your side. I said 1.5
because that's what I have been noticing and trying to fix it. It breaks my vertical alignment.
If it's my fault then I will apologize for sure!
Thanks for the info. Just as I suspected, you're asking for something that this repo is not made for. Like I mentioned before, your issue is a matter of how much space is reserved for characters in a terminal. Again, use mattn/go-runewidth
for that.
In the web version you posted, the issue is more complicated. The font IBM Plex Sans is used but it does not contain Asian characters so it will be replaced by whatever your operating system uses for Asian characters as default. For me, it's something like "PingFang SC". The width of a character depends on whatever that font sets as a width.
I'm closing this issue. There's nothing to do for me here and I gave you enough information to pursue this topic further on your own. Good luck!
Thanks! I apologize if this issue was offensive!
I am using this module for my CLI and I can't seem to get characters like Japanese and Chinese to working.
After some digging up I found that each char has a width of
1.5
not1
. So I think it to solve it. We can check if the character is from that specific range then multiply it by1.5
and them round it off so it can work. There can be better solutions but this is one that I can think of!I don't know any terminal which supports my module with these character sets.