garybernhardt / selecta

A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.
MIT License
1.34k stars 81 forks source link

Coloring matched portion? #67

Closed JoshCheek closed 9 years ago

JoshCheek commented 9 years ago

Favourite aspect of ag / ack is how they colour the matched portion. Thoughts on adding this to selecta?

screenshot 2015-01-05 09 29 59

garybernhardt commented 9 years ago

I'm afraid of the color choice not working well on all color schemes (light background, dark background, weird stuff like solarized). We could just use ack's choice (red), which is probably reasonable. But then someone is going to want to change it, and I'm not willing to support custom color configuration, which leads me back to "I don't want to do this"...

garybernhardt commented 9 years ago

Some other changes on a branch made it easy to try this out, so I did: screen shot 2015-01-14 at 2 02 26 pm

I like it quite a bit. It certainly makes understanding the matching easier. Maybe I should get over the fear of colors not working. If it's good enough for ack, it's probably good enough for selecta. However, there may still be a nontrivial performance cost depending on what the algorithm ends up being, so we'll see.

rschmitt commented 9 years ago

For what it's worth, I implemented this a bit differently in Heatseeker: screen shot 2015-02-24 at 9 47 28 pm I've come to prefer the picking out of individual characters, because it can actually serve to highlight the non-matching portions of the strings, making it easier to see how matches are different. Here's another example: screen shot 2015-02-24 at 9 49 06 pm

garybernhardt commented 9 years ago

I thought about doing that, but I'm almost positive that the allocations would kill performance. Welp!

rschmitt commented 9 years ago

I actually compute the scores a second time in order to render the matches. There's a separate scoring function that returns low-level details about matching character indices. And since there's a hard limit on the number of matches that will be displayed, the cost is essentially constant for each draw_screen call.

garybernhardt commented 9 years ago

Ahh, yeah, that crossed my mind as well, but I thought it would be gross to maintain. Maybe I'll make an attempt.

garybernhardt commented 9 years ago

This is merged into master as of d874c99dd7f0f94225a95da06fc487b0fa5b9edc.