-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.go
81 lines (64 loc) · 1.67 KB
/
options.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package input
import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
type Option func(*Model)
func WithTeaProgramOpts(opts ...tea.ProgramOption) Option {
return func(m *Model) {
m.teaProgramOpts = append(m.teaProgramOpts, opts...)
}
}
func WithHelp(show bool) Option {
return func(m *Model) {
m.showHelp = show
}
}
func WithKeyMap(keyMap KeyMap) Option {
return func(m *Model) {
m.keys = keyMap
}
}
type EchoMode = textinput.EchoMode
const (
// EchoNormal displays text as is. This is the default behavior.
EchoNormal EchoMode = textinput.EchoNormal
// EchoPassword displays the EchoCharacter mask instead of actual
// characters. This is commonly used for password fields.
EchoPassword EchoMode = textinput.EchoPassword
// EchoNone displays nothing as characters are entered. This is commonly
// seen for password fields on the command line.
EchoNone EchoMode = textinput.EchoNone
)
func WithEchoMode(mode EchoMode) Option {
return func(m *Model) {
m.WithEchoMode(mode)
}
}
type InputMode int
const (
InputAll InputMode = iota // allow any input.
InputInteger // only integers can be entered.
InputNumber // only integers and decimals can be entered.
)
func WithInputMode(mode InputMode) Option {
return func(m *Model) {
m.WithInputMode(mode)
}
}
type ValidateFunc func(string) error
func WithValidateFunc(vf ValidateFunc) Option {
return func(m *Model) {
m.WithValidateFunc(vf)
}
}
func WithWidth(width int) Option {
return func(m *Model) {
m.textInput.Width = width
}
}
func WithCharLimit(limit int) Option {
return func(m *Model) {
m.textInput.CharLimit = limit
}
}