summaryrefslogtreecommitdiff
path: root/src/terminal.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-02-12 20:15:04 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-02-12 20:15:04 +0900
commit84e2262ad63df2112f16b2a80fc661294c3da45e (patch)
tree803f4bf41de9d0011efcc2e29f788ac990fc7c73 /src/terminal.go
parent378137d34a2a11b16c66dff2bf4309c7ce232a94 (diff)
downloadfzf-84e2262ad63df2112f16b2a80fc661294c3da45e.tar.gz
Make --accept-nth and --with-nth support templates
Diffstat (limited to 'src/terminal.go')
-rw-r--r--src/terminal.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 273f2650..9a4abf86 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -305,7 +305,7 @@ type Terminal struct {
nthAttr tui.Attr
nth []Range
nthCurrent []Range
- acceptNth []Range
+ acceptNth func([]Token) string
tabstop int
margin [4]sizeSpec
padding [4]sizeSpec
@@ -919,7 +919,6 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
nthAttr: opts.Theme.Nth.Attr,
nth: opts.Nth,
nthCurrent: opts.Nth,
- acceptNth: opts.AcceptNth,
tabstop: opts.Tabstop,
hasStartActions: false,
hasResultActions: false,
@@ -961,6 +960,9 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
lastAction: actStart,
lastFocus: minItem.Index(),
numLinesCache: make(map[int32]numLinesCacheValue)}
+ if opts.AcceptNth != nil {
+ t.acceptNth = opts.AcceptNth(t.delimiter)
+ }
// This should be called before accessing tui.Color*
tui.InitTheme(opts.Theme, renderer.DefaultTheme(), opts.Black, opts.InputBorderShape.Visible(), opts.HeaderBorderShape.Visible())
@@ -1570,9 +1572,11 @@ func (t *Terminal) output() bool {
transform := func(item *Item) string {
return item.AsString(t.ansi)
}
- if len(t.acceptNth) > 0 {
+ if t.acceptNth != nil {
transform = func(item *Item) string {
- return JoinTokens(StripLastDelimiter(Transform(Tokenize(item.AsString(t.ansi), t.delimiter), t.acceptNth), t.delimiter))
+ tokens := Tokenize(item.AsString(t.ansi), t.delimiter)
+ transformed := t.acceptNth(tokens)
+ return StripLastDelimiter(transformed, t.delimiter)
}
}
found := len(t.selected) > 0