mirror of
https://github.com/charmbracelet/gum
synced 2024-05-12 19:26:38 +02:00
fix(filter): made filter work with lists as choose (#424)
* made filter work with lists as choose * lint fix * response to code review
This commit is contained in:
parent
77aa8640f2
commit
971b6cf16f
|
@ -33,17 +33,15 @@ func (o Options) Run() error {
|
|||
|
||||
v := viewport.New(o.Width, o.Height)
|
||||
|
||||
var choices []string
|
||||
if input, _ := stdin.Read(); input != "" {
|
||||
input = strings.TrimSuffix(input, "\n")
|
||||
if input != "" {
|
||||
choices = strings.Split(input, "\n")
|
||||
if len(o.Options) == 0 {
|
||||
if input, _ := stdin.Read(); input != "" {
|
||||
o.Options = strings.Split(strings.TrimSuffix(input, "\n"), "\n")
|
||||
} else {
|
||||
o.Options = files.List()
|
||||
}
|
||||
} else {
|
||||
choices = files.List()
|
||||
}
|
||||
|
||||
if len(choices) == 0 {
|
||||
if len(o.Options) == 0 {
|
||||
return errors.New("no options provided, see `gum filter --help`")
|
||||
}
|
||||
|
||||
|
@ -58,19 +56,19 @@ func (o Options) Run() error {
|
|||
}
|
||||
switch {
|
||||
case o.Value != "" && o.Fuzzy:
|
||||
matches = fuzzy.Find(o.Value, choices)
|
||||
matches = fuzzy.Find(o.Value, o.Options)
|
||||
case o.Value != "" && !o.Fuzzy:
|
||||
matches = exactMatches(o.Value, choices)
|
||||
matches = exactMatches(o.Value, o.Options)
|
||||
default:
|
||||
matches = matchAll(choices)
|
||||
matches = matchAll(o.Options)
|
||||
}
|
||||
|
||||
if o.NoLimit {
|
||||
o.Limit = len(choices)
|
||||
o.Limit = len(o.Options)
|
||||
}
|
||||
|
||||
p := tea.NewProgram(model{
|
||||
choices: choices,
|
||||
choices: o.Options,
|
||||
indicator: o.Indicator,
|
||||
matches: matches,
|
||||
header: o.Header,
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
|
||||
// Options is the customization options for the filter command.
|
||||
type Options struct {
|
||||
Options []string `arg:"" optional:"" help:"Options to filter."`
|
||||
|
||||
Indicator string `help:"Character for selection" default:"•" env:"GUM_FILTER_INDICATOR"`
|
||||
IndicatorStyle style.Styles `embed:"" prefix:"indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_INDICATOR_"`
|
||||
Limit int `help:"Maximum number of options to pick" default:"1" group:"Selection"`
|
||||
|
|
Loading…
Reference in a new issue