Closed untitaker closed 9 years ago
Note that this issue only occurs on rather narrow terminal widths, somewhat smaller than 80 chars or so.
I've found a very simple algorithm for tab-expansion: http://stackoverflow.com/a/8900610
This would fix this issue and #73. It seems to output the same things as the expand
command for ASCII input, umlauts, however, don't seem to be treated correctly (it's off by one character). So yeah, it counts bytes instead of graphemes. But I don't think it's important whether the UI does such incorrect things (which probably aren't even noticed), as long as it doesn't completely break!
Fixed with the code you linked to. Tabs are the worst.
On further thought, there are probably other graphemes whose column width differs from their amount of bytes in utf8.
Selecta operates on graphemes (Ruby "chars"), so it does do the right thing. This example with Unicode snowmen should work just fine, for example:
python3 -c '[print("☃foo" * 200) for i in range(30)]' | selecta
Actually, @untitaker is right. Selecta does not place the cursor in the correct location when CJK characters are included in the query: By contrast, here is how Heatseeker renders the query: This was easy to get right in Heatseeker, because all I had to do was call this function from the Rust standard library. In the Ruby case, I'm not sure how you would fix this without taking a dependency on a gem.
2a08d045af1abadd1cb1ebd8fdeabf7e5dbf30a7 should fix that. I took the easy way out: draw the query last, so the cursor naturally lands at the end of it. No need to compute the display length of the query. You could still construct a case where Selecta truncates strings in the candidate list more than it needs to, but that's very minor and I doubt that anyone will even notice.
The following command:
looks like this:
When I start typing, the cursor is still somewhere inbetween the suggestions:
Functionality-wise selecta works fine. This seems to occur only when the available suggestions exceed the screen's height.
This also occurs under zsh :P