itor/gui/model.go

65 lines
1.7 KiB
Go

package gui
import (
"gitea.tyrel.dev/tyrel/itor/models"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
)
type model struct {
deck []models.Card // items on the to-do list
selectCardIndex int // which to-do list item our selectCardIndex is pointing at
selected map[int]struct{} // which to-do items are selected
selectList list.Model
createInputs []textinput.Model // Inputs for front and back, is an array because we change position by an index
createdInputIndex int // holds an index for which input is active editing in create mode
mode Mode
err error
}
func initialModel() model {
front := textinput.New()
front.Placeholder = "Front..."
front.Focus()
front.CharLimit = 256
front.Width = 80
back := textinput.New()
back.Placeholder = "Back..."
back.CharLimit = 256
back.Width = 80
deck := []models.Card{
models.NewCard("Hello (JP)", "Konnichi wa"),
models.NewCard("Hello (SP)", "Hola"),
models.NewCard("Hello (DE)", "Guten Tag"),
}
var items []list.Item
for _, card := range deck {
items = append(items, card)
}
selectedList := list.New(items, itemDelegate{}, 80, 8)
selectedList.Title = "Card selection"
selectedList.SetShowStatusBar(false)
selectedList.SetFilteringEnabled(false)
selectedList.SetShowHelp(false)
selectedList.SetFilteringEnabled(false)
selectedList.Styles.Title = titleStyle
selectedList.Styles.PaginationStyle = paginationStyle
selectedList.Styles.HelpStyle = helpStyle
return model{
deck: deck,
selectList: selectedList,
createInputs: []textinput.Model{front, back},
selected: make(map[int]struct{}),
mode: Select,
}
}