-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
45 lines (37 loc) · 1.14 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cprompt
import (
prompt "github.com/aschey/bubbleprompt"
"github.com/aschey/bubbleprompt/input/commandinput"
)
type Option[T any] func(model *Model[T])
func WithIgnoreCmds[T any](cmds ...string) Option[T] {
return func(model *Model[T]) {
model.SetIgnoreCmds(cmds...)
}
}
func WithOnCompleterStart[T any](onCompleterStart CompleterStart[T]) Option[T] {
return func(model *Model[T]) {
model.app.onCompleterStart = onCompleterStart
}
}
func WithOnCompleterFinish[T any](onCompleterStart CompleterFinish[T]) Option[T] {
return func(model *Model[T]) {
model.app.onCompleterFinish = onCompleterStart
}
}
func WithOnExecutorStart[T any](onExecutorStart ExecutorStart[T]) Option[T] {
return func(model *Model[T]) {
model.app.onExecutorStart = onExecutorStart
}
}
func WithOnExecutorFinish[T any](onExecutorFinish ExecutorFinish) Option[T] {
return func(model *Model[T]) {
model.app.onExecutorFinish = onExecutorFinish
}
}
func WithPromptOptions[T any](options ...prompt.Option[commandinput.CommandMetadata[T]]) Option[T] {
return func(model *Model[T]) {
prompt := buildAppModel(*model.app, options...)
model.prompt = prompt
}
}