File: filter_spec.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (23 lines) | stat: -rw-r--r-- 609 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package modes

import (
	"strings"

	"src.elv.sh/pkg/ui"
)

// FilterSpec specifies the configuration for the filter in listing modes.
type FilterSpec struct {
	// Called with the filter text to get the filter predicate. If nil, the
	// predicate performs substring match.
	Maker func(string) func(string) bool
	// Highlighter for the filter. If nil, the filter will not be highlighted.
	Highlighter func(string) (ui.Text, []ui.Text)
}

func (f FilterSpec) makePredicate(p string) func(string) bool {
	if f.Maker == nil {
		return func(s string) bool { return strings.Contains(s, p) }
	}
	return f.Maker(p)
}