Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from May 5, 2024

Conversation

kuremu
Copy link
Contributor

@kuremu kuremu commented May 4, 2024

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).

kuremu added 2 commits May 4, 2024 12:32
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.
Copy link
Owner

@junegunn junegunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the man page as well.

man/man1/fzf.1 Outdated Show resolved Hide resolved
man/man1/fzf.1 Outdated Show resolved Hide resolved
src/terminal.go Outdated Show resolved Hide resolved
src/terminal.go Outdated Show resolved Hide resolved
man/man1/fzf.1 Outdated Show resolved Hide resolved
After some testing, I decided that we should not reset the variables.
Because if we do that, the information becomes unavailable to the
preview process as it runs asynchronously in a different goroutine.

  fzf --header-lines=2 --bind 'click-header:transform-prompt(printf ${FZF_CLICK_HEADER_LINE}x${FZF_CLICK_HEADER_COLUMN})+preview(env | grep FZF)'
@junegunn junegunn merged commit 7b98c2c into junegunn:master May 5, 2024
5 checks passed
@junegunn
Copy link
Owner

junegunn commented May 5, 2024

Merged, thanks!

@kuremu
Copy link
Contributor Author

kuremu commented May 5, 2024

Glad to contribute! Thanks

@kuremu kuremu deleted the header-click branch May 5, 2024 10:47
@junegunn
Copy link
Owner

junegunn commented May 5, 2024

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.

junegunn added a commit that referenced this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants