first commit
This commit is contained in:
commit
5203032b83
25 changed files with 2825 additions and 0 deletions
64
setup/fields/checkbox.go
Normal file
64
setup/fields/checkbox.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package fields
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type CheckboxModel struct {
|
||||
Label string
|
||||
Checked bool
|
||||
}
|
||||
|
||||
func NewCheckboxModel(label string, checked bool) *CheckboxModel {
|
||||
return &CheckboxModel{
|
||||
Label: label,
|
||||
Checked: checked,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) Update(msg tea.Msg) (FieldModel, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case " ", "enter":
|
||||
m.Checked = !m.Checked
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) View() string {
|
||||
res := ""
|
||||
res += m.Label + ": "
|
||||
if m.Checked {
|
||||
res += "[x]"
|
||||
} else {
|
||||
res += "[ ]"
|
||||
}
|
||||
return res
|
||||
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) Focus() {
|
||||
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) Blur() {
|
||||
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) CaptureKeys() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) GetLabel() string {
|
||||
return m.Label
|
||||
}
|
||||
|
||||
func (m *CheckboxModel) GetValue() interface{} {
|
||||
return m.Checked
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue