diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-11-23 21:05:11 -0500 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-11-23 21:05:11 -0500 |
commit | 4d25e4ece0b72d240bb2565f8abb7389e650990a (patch) | |
tree | 55af982b45d9ed576871c6f3ccf5f800cddc9b56 /internal/switcher | |
parent | b42ab480dd4c4eec83d79bba9400232ddb79f6b1 (diff) |
Preview + Unit-tests for color conversions
Diffstat (limited to 'internal/switcher')
-rw-r--r-- | internal/switcher/switcher.go | 14 |
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...) } |