rschmitt / heatseeker

A high-performance Selecta clone, written in Rust.
MIT License
214 stars 10 forks source link

Terminate on ESC and Ctrl+[ - would you like a contribution? #24

Closed ghost closed 5 years ago

ghost commented 7 years ago

I am using heatseeker for my reverse-search implementation (the one coming up when pressing ctrl+R in bash/zsh), and noticed that it doesn't behave intuitively to me quite yet because some keybindings are missing.

Would you like me to contribute support for this?

rschmitt commented 7 years ago

I would, this feature makes perfect sense. I guess I never thought to add it because I got used to using C-g instead. Can you also include a Windows implementation? The virtual-key code is VK_ESCAPE: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx

ghost commented 7 years ago

Hi @rschmitt, thanks for your reply. After further testing heatseeker I realized it's not quite ready yet as a ctrl+R replacement. One reason is that it does not prefer (i.e. does not seem to know) more recent entries of the history file, and the screen refresh is very flickery. That is why I just switched to using fzf, which seems to do it all just perfectly. It's just that I would have preferred a Rust implementation, but Go is quite fine for 10k lines of history lines too :).

rschmitt commented 7 years ago

Did you try invoking hs with --filter-only? That will cause it to prefer recent entries.

rschmitt commented 7 years ago

Here's my shell function for history handling:

# Replace the shell's built-in ^R handling
fuzzy_history() {
    echo
    BUFFER=$(history 1 | sort -n -r | perl -ne 's/^\s*[0-9]+\*?\s+//; print unless $seen{$_}++' | hs --filter-only)
    echo -n "\033[1A"
    zle accept-search
    zle reset-prompt
    zle end-of-line
}

zle -N fuzzy_history
bindkey "^R" "fuzzy_history"
rschmitt commented 7 years ago

By the way, I agree with you about the flickery redraws, but I think that I can fix that on the POSIX side with some simple buffering.

rschmitt commented 7 years ago

@Byron-TW Can you try the latest commit, a2216886fda79e2a011eee01d4a5f1c83bc358e1? The screen refresh flickering should be significantly improved.

ghost commented 7 years ago

Thanks for your effort! heatseeker 1.5.0 multi-threaded (a221688) (built 2017-02-02 16:36:20 +0100 for x86_64-apple-darwin) still showed the flickering issue, unfortunately. Please note that I am using alacritty, which delivers 60fps constantly, which might make the issue more pronounced than it actually is.

I have also tried the function you provided, but it seemed that the it would now prefer recent lines even though their match was actually worse. I don't know how fzf does it, but it just yields the results I would expect. Maybe you can compare the results and see what they do differnently - right now hs seems to be the best contender from the Rust world.

rschmitt commented 7 years ago

You're using alacritty? In that case you need to build alacritty from the save-restore-cursor branch (c247acf), otherwise heatseeker cannot function correctly at all. I specifically tested build a221688 of hs on alacritty.

ghost commented 7 years ago

Wow, thanks for pointing this out. I didn't get to try it yet, but trust you it is working. Once it has been merged into master, I will benefit from it as well! Thanks so much for your work!