💄 style(ui): spinners
This commit is contained in:
parent
b556cdfa22
commit
82e585c5a5
1 changed files with 26 additions and 5 deletions
31
main.go
31
main.go
|
@ -3,9 +3,11 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
|
"github.com/charmbracelet/bubbles/spinner"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
gloss "github.com/charmbracelet/lipgloss"
|
gloss "github.com/charmbracelet/lipgloss"
|
||||||
"github.com/charmbracelet/lipgloss/list"
|
"github.com/charmbracelet/lipgloss/list"
|
||||||
|
@ -21,13 +23,19 @@ type menu struct {
|
||||||
keys keyMap
|
keys keyMap
|
||||||
help help.Model
|
help help.Model
|
||||||
inputStyle gloss.Style
|
inputStyle gloss.Style
|
||||||
|
spinner spinner.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel() menu {
|
func initialModel() menu {
|
||||||
|
s := spinner.New()
|
||||||
|
s.Spinner = spinner.MiniDot
|
||||||
|
s.Style = gloss.NewStyle().Foreground(gloss.Color("3"))
|
||||||
|
|
||||||
return menu{
|
return menu{
|
||||||
current: 3,
|
current: 3,
|
||||||
keys: keys,
|
keys: keys,
|
||||||
help: help.New(),
|
help: help.New(),
|
||||||
|
spinner: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,10 +149,13 @@ func readYaml() tea.Msg {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m menu) Init() tea.Cmd {
|
func (m menu) Init() tea.Cmd {
|
||||||
return readYaml
|
return tea.Batch(readYaml, m.spinner.Tick)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
var cmd tea.Cmd
|
||||||
|
var cmds []tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
|
||||||
case yamlMsg:
|
case yamlMsg:
|
||||||
|
@ -156,9 +167,13 @@ func (m menu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case "ctrl+c", "q":
|
case "ctrl+c", "q":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case spinner.TickMsg:
|
||||||
|
m.spinner, cmd = m.spinner.Update(msg)
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m menu) View() string {
|
func (m menu) View() string {
|
||||||
|
@ -177,7 +192,7 @@ func (m menu) View() string {
|
||||||
|
|
||||||
softwareListEnumerator := func(l list.Items, i int) string {
|
softwareListEnumerator := func(l list.Items, i int) string {
|
||||||
if m.current == i {
|
if m.current == i {
|
||||||
return ">"
|
return m.spinner.View()
|
||||||
} else if m.current > i {
|
} else if m.current > i {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -186,8 +201,14 @@ func (m menu) View() string {
|
||||||
|
|
||||||
software := list.New().Enumerator(softwareListEnumerator)
|
software := list.New().Enumerator(softwareListEnumerator)
|
||||||
|
|
||||||
for _, item := range m.order {
|
keys := make([]string, 0, len(m.order))
|
||||||
software.Item(item.Name)
|
for k := range m.order {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, k := range keys {
|
||||||
|
software.Item(m.order[k].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
sidebarContent := software.String()
|
sidebarContent := software.String()
|
||||||
|
|
Loading…
Reference in a new issue