src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/cli/modes/filter_spec.go (about)

     1  package modes
     2  
     3  import (
     4  	"strings"
     5  
     6  	"src.elv.sh/pkg/ui"
     7  )
     8  
     9  // FilterSpec specifies the configuration for the filter in listing modes.
    10  type FilterSpec struct {
    11  	// Called with the filter text to get the filter predicate. If nil, the
    12  	// predicate performs substring match.
    13  	Maker func(string) func(string) bool
    14  	// Highlighter for the filter. If nil, the filter will not be highlighted.
    15  	Highlighter func(string) (ui.Text, []ui.Text)
    16  }
    17  
    18  func (f FilterSpec) makePredicate(p string) func(string) bool {
    19  	if f.Maker == nil {
    20  		return func(s string) bool { return strings.Contains(s, p) }
    21  	}
    22  	return f.Maker(p)
    23  }