Skip to content

Commit 664ee1f

Browse files
committed
Add change-pointer and transform-pointer
Close #4178
1 parent dac5b6f commit 664ee1f

6 files changed

Lines changed: 103 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
# Display "Type to search" when the input is empty
99
fzf --ghost "Type to search"
1010
```
11+
- Added `change-pointer` and `transform-pointer` actions for dynamically changing the pointer sign
1112
- Bug fixes and improvements
1213

1314
0.60.3

man/man1/fzf.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
THE SOFTWARE.
2323
..
24-
.TH fzf 1 "Mar 2025" "fzf 0.60.3" "fzf - a command-line fuzzy finder"
24+
.TH fzf 1 "Mar 2025" "fzf 0.61.0" "fzf - a command-line fuzzy finder"
2525

2626
.SH NAME
2727
fzf - a command-line fuzzy finder
@@ -1616,6 +1616,7 @@ A key or an event can be bound to one or more of the following actions.
16161616
\fBchange\-multi\fR (enable multi-select mode with no limit)
16171617
\fBchange\-multi(...)\fR (enable multi-select mode with a limit or disable it with 0)
16181618
\fBchange\-nth(...)\fR (change \fB\-\-nth\fR option; rotate through the multiple options separated by '|')
1619+
\fBchange\-pointer(...)\fR (change \fB\-\-pointer\fR option)
16191620
\fBchange\-preview(...)\fR (change \fB\-\-preview\fR option)
16201621
\fBchange\-preview\-label(...)\fR (change \fB\-\-preview\-label\fR to the given string)
16211622
\fBchange\-preview\-window(...)\fR (change \fB\-\-preview\-window\fR option; rotate through the multiple option sets separated by '|')
@@ -1709,6 +1710,7 @@ A key or an event can be bound to one or more of the following actions.
17091710
\fBtransform\-input\-label(...)\fR (transform input label using an external command)
17101711
\fBtransform\-list\-label(...)\fR (transform list label using an external command)
17111712
\fBtransform\-nth(...)\fR (transform nth using an external command)
1713+
\fBtransform\-pointer(...)\fR (transform pointer using an external command)
17121714
\fBtransform\-preview\-label(...)\fR (transform preview label using an external command)
17131715
\fBtransform\-prompt(...)\fR (transform prompt string using an external command)
17141716
\fBtransform\-query(...)\fR (transform query string using an external command)

src/actiontype_string.go

Lines changed: 47 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ const (
14041404

14051405
func init() {
14061406
executeRegexp = regexp.MustCompile(
1407-
`(?si)[:+](become|execute(?:-multi|-silent)?|reload(?:-sync)?|preview|(?:change|transform)-(?:query|prompt|(?:border|list|preview|input|header)-label|header|search|nth)|transform|change-(?:preview-window|preview|multi)|(?:re|un|toggle-)bind|pos|put|print|search)`)
1407+
`(?si)[:+](become|execute(?:-multi|-silent)?|reload(?:-sync)?|preview|(?:change|transform)-(?:query|prompt|(?:border|list|preview|input|header)-label|header|search|nth|pointer)|transform|change-(?:preview-window|preview|multi)|(?:re|un|toggle-)bind|pos|put|print|search)`)
14081408
splitRegexp = regexp.MustCompile("[,:]+")
14091409
actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")
14101410
}
@@ -1799,6 +1799,8 @@ func isExecuteAction(str string) actionType {
17991799
return actChangeInputLabel
18001800
case "change-header-label":
18011801
return actChangeHeaderLabel
1802+
case "change-pointer":
1803+
return actChangePointer
18021804
case "change-preview-window":
18031805
return actChangePreviewWindow
18041806
case "change-preview":
@@ -1839,6 +1841,8 @@ func isExecuteAction(str string) actionType {
18391841
return actTransformHeader
18401842
case "transform-nth":
18411843
return actTransformNth
1844+
case "transform-pointer":
1845+
return actTransformPointer
18421846
case "transform-prompt":
18431847
return actTransformPrompt
18441848
case "transform-query":

src/terminal.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,14 @@ const (
547547
actTransformHeader
548548
actTransformHeaderLabel
549549
actTransformNth
550+
actTransformPointer
550551
actTransformPreviewLabel
551552
actTransformPrompt
552553
actTransformQuery
553554
actTransformSearch
554555
actSearch
555556
actPreview
557+
actChangePointer
556558
actChangePreview
557559
actChangePreviewWindow
558560
actPreviewTop
@@ -5951,6 +5953,21 @@ func (t *Terminal) Loop() error {
59515953
}
59525954
}
59535955
}
5956+
case actChangePointer, actTransformPointer:
5957+
pointer := a.a
5958+
if a.t == actTransformPointer {
5959+
pointer = t.captureLine(a.a)
5960+
}
5961+
length := uniseg.StringWidth(pointer)
5962+
if length <= 2 {
5963+
if length != t.pointerLen {
5964+
t.forceRerenderList()
5965+
}
5966+
t.pointer = pointer
5967+
t.pointerLen = length
5968+
t.pointerEmpty = strings.Repeat(" ", t.pointerLen)
5969+
req(reqList)
5970+
}
59545971
case actChangePreview:
59555972
if t.previewOpts.command != a.a {
59565973
t.previewOpts.command = a.a

test/test_core.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,4 +1890,34 @@ def test_search_override_query_in_no_input_mode
18901890
tmux.send_keys :Space
18911891
tmux.until { |lines| assert_includes lines, '> 777' }
18921892
end
1893+
1894+
def test_change_pointer
1895+
tmux.send_keys %(seq 2 | #{FZF} --bind 'a:change-pointer(a),b:change-pointer(bb),c:change-pointer(),d:change-pointer(ddd)'), :Enter
1896+
tmux.until { |lines| assert_includes lines, '> 1' }
1897+
tmux.send_keys 'a'
1898+
tmux.until { |lines| assert_includes lines, 'a 1' }
1899+
tmux.send_keys 'b'
1900+
tmux.until { |lines| assert_includes lines, 'bb 1' }
1901+
tmux.send_keys 'c'
1902+
tmux.until { |lines| assert_includes lines, ' 1' }
1903+
tmux.send_keys 'd'
1904+
tmux.until { |lines| refute_includes lines, 'ddd 1' }
1905+
tmux.send_keys :Up
1906+
tmux.until { |lines| assert_includes lines, ' 2' }
1907+
end
1908+
1909+
def test_transform_pointer
1910+
tmux.send_keys %(seq 2 | #{FZF} --bind 'a:transform-pointer(echo a),b:transform-pointer(echo bb),c:transform-pointer(),d:transform-pointer(echo ddd)'), :Enter
1911+
tmux.until { |lines| assert_includes lines, '> 1' }
1912+
tmux.send_keys 'a'
1913+
tmux.until { |lines| assert_includes lines, 'a 1' }
1914+
tmux.send_keys 'b'
1915+
tmux.until { |lines| assert_includes lines, 'bb 1' }
1916+
tmux.send_keys 'c'
1917+
tmux.until { |lines| assert_includes lines, ' 1' }
1918+
tmux.send_keys 'd'
1919+
tmux.until { |lines| refute_includes lines, 'ddd 1' }
1920+
tmux.send_keys :Up
1921+
tmux.until { |lines| assert_includes lines, ' 2' }
1922+
end
18931923
end

0 commit comments

Comments
 (0)