first commit
This commit is contained in:
commit
5203032b83
25 changed files with 2825 additions and 0 deletions
69
setup/list.go
Normal file
69
setup/list.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package setup
|
||||
|
||||
import (
|
||||
"bubble/setup/ui"
|
||||
"bubble/types"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type ListModel struct {
|
||||
options []string
|
||||
focus int
|
||||
}
|
||||
|
||||
func NewListModel(applications []types.PackageApplication) *ListModel {
|
||||
options := make([]string, len(applications))
|
||||
for i, app := range applications {
|
||||
options[i] = app.Name
|
||||
}
|
||||
return &ListModel{
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ListModel) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
case "up", "w", "shift+tab":
|
||||
m.focus--
|
||||
if m.focus < 0 {
|
||||
m.focus = len(m.options) - 1
|
||||
}
|
||||
case "down", "s", "tab":
|
||||
m.focus++
|
||||
if m.focus == len(m.options) {
|
||||
m.focus = 0
|
||||
}
|
||||
case "enter":
|
||||
return m, func() tea.Msg {
|
||||
return types.SelectedAppMsg{Index: m.focus}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m *ListModel) View() string {
|
||||
res := ""
|
||||
listStyle := lipgloss.NewStyle().Padding(1, 1).Foreground(ui.ColorPurple)
|
||||
for i := range m.options {
|
||||
if i == m.focus {
|
||||
res += "[x] " + m.options[i]
|
||||
} else {
|
||||
res += "[ ] " + m.options[i]
|
||||
}
|
||||
if i != len(m.options)-1 {
|
||||
res += "\n"
|
||||
}
|
||||
}
|
||||
return listStyle.Render(res)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue