Skip to content

Commit abf4720

Browse files
authored
feat: add filter support (#22)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 8c91521 commit abf4720

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cli/root.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func NewRootCommand(execer exec.Execer, out io.Writer) (cmd *cobra.Command) {
3737
flags.BoolVarP(&opt.loop, "loop", "", true, "Run the Markdown in loop mode.")
3838
flags.BoolVarP(&opt.keepFilter, "keep-filter", "", true, "Indicate if keep the filter.")
3939
flags.BoolVarP(&opt.keepScripts, "keep-scripts", "", false, "Indicate if keep the temporary scripts.")
40-
flags.IntVarP(&opt.pageSize, "page-size", "", 6, "Number of the select items.")
40+
flags.IntVarP(&opt.pageSize, "page-size", "", 8, "Number of the select items.")
41+
flags.StringVarP(&opt.filter, "filter", "", "", "Filter of the scripts")
4142
return
4243
}
4344

@@ -157,6 +158,7 @@ type option struct {
157158
keepFilter bool
158159
keepScripts bool
159160
pageSize int
161+
filter string
160162

161163
execer exec.Execer
162164
}
@@ -168,10 +170,19 @@ func (o *option) executeScripts(scriptRunners ScriptRunners) (err error) {
168170
selector := &survey.MultiSelect{
169171
Message: "Choose the code block to run",
170172
Options: scriptRunners.GetTitles(),
173+
VimMode: true,
171174
}
172175
var titles []string
173176
if err = survey.AskOne(selector, &titles,
174177
survey.WithKeepFilter(o.keepFilter),
178+
survey.WithFilter(func(filter, value string, index int) (include bool) {
179+
include = true
180+
value = strings.ToLower(value)
181+
if o.filter != "" && value != "quit" {
182+
include = strings.Contains(value, o.filter)
183+
}
184+
return
185+
}),
175186
survey.WithPageSize(o.pageSize)); err != nil {
176187
return
177188
}

0 commit comments

Comments
 (0)