junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.33k stars 2.38k forks source link

feature: header-click event for reporting clicks within header #3768

Closed kuremu closed 5 months ago

kuremu commented 5 months ago

Sets FZF_HEADERCLICK_LINE and FZF_HEADERCLICK_COLUMN env vars with coordinates of last click inside and relative to the header and fires header-click event.

printf "header1\nheader2\nheader3\na\nb\nc" | fzf --header-lines=3 --bind "header-click:transform-prompt(echo \${FZF_HEADERCLICK_LINE}x\${FZF_HEADERCLICK_COLUMN})"

Could be useful for eg. selecting a sort column. Could set a FZF_HEADERCLICK_WORD var as well if that is more useful to people.

Here is a more complex demo with an interactive keyboard (invoke like cat /usr/share/dict/words | python keyboard.py).

junegunn commented 5 months ago

Merged, thanks!

kuremu commented 5 months ago

Glad to contribute! Thanks

junegunn commented 5 months ago

Hmm, I think we should reconsider how to report the line number as it can be confusing when you use multi-line --header.

Unlike --header-lines, multi-line --headers are always displayed from top to bottom, so in the following case,

fzf --header $'1. hello\n2. world' --header-first \
  --bind 'click-header:transform-prompt:echo ${FZF_CLICK_HEADER_LINE}x${FZF_CLICK_HEADER_COLUMN}'

clicking on 1. hello reports line 2.

But when you're in --reverse layout, it will report line 1.

fzf --header $'1. hello\n2. world' --header-first \
  --bind 'click-header:transform-prompt:echo ${FZF_CLICK_HEADER_LINE}x${FZF_CLICK_HEADER_COLUMN}'

This gets even more confusing when you use both --header and --header-lines.

Should we always count from the top? Let me think about that.