summaryrefslogtreecommitdiff
path: root/internal/switcher/switcher.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/switcher/switcher.go')
-rw-r--r--internal/switcher/switcher.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go
index d542df1..0680996 100644
--- a/internal/switcher/switcher.go
+++ b/internal/switcher/switcher.go
@@ -5,19 +5,23 @@ import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/bubbletea-app-template/internal/colors"
"github.com/charmbracelet/bubbletea-app-template/internal/picker"
+ "github.com/charmbracelet/bubbletea-app-template/internal/preview"
"github.com/charmbracelet/bubbletea-app-template/internal/quit"
)
type Model struct {
active int
pickers []picker.Model
+ preview preview.Model
}
func New(pickers []picker.Model) Model {
return Model{
active: 0,
pickers: pickers,
+ preview: *preview.New(colors.Hex(pickers[0].GetColor())),
}
}
@@ -53,7 +57,7 @@ func (m Model) View() string {
v += fmt.Sprintf(" %s |", p.Title())
}
}
- return fmt.Sprintf("%s\n%s", v, m.pickers[m.active].View())
+ return fmt.Sprintf("%s\n%s\n%s", v, m.pickers[m.active].View(), m.preview.View())
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -74,9 +78,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return quit.Model{}, tea.Quit
// return m, tea.Quit
default:
+ // Update the picker
newActive, cmd := m.pickers[m.active].Update(msg)
m.pickers[m.active] = newActive.(picker.Model)
cmds = append(cmds, cmd)
+ // Update the preview
+ newPreview := preview.New(colors.Hex(m.pickers[m.active].GetColor()))
+ m.preview = *newPreview
+
return m, tea.Batch(cmds...)
}
}
@@ -85,5 +94,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.pickers[i] = newActive.(picker.Model)
cmds = append(cmds, cmd)
}
+ // Update the preview
+ newPreview := preview.New(colors.Hex(m.pickers[m.active].GetColor()))
+ m.preview = *newPreview
return m, tea.Batch(cmds...)
}