github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/cli/mode/filter_spec.go (about)

     1  package mode
     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 higlighted.
    15  	Highlighter func(string) (ui.Text, []error)
    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  }