on main help sign in
fix(ui): handle model selection in models dialog
98df293Ayman Bagabas
internal/ui/dialog/messages.go+7
@@ -2,6 +2,7 @@ package dialog
2
2
3import (
3import (
4 tea "charm.land/bubbletea/v2"
4 tea "charm.land/bubbletea/v2"
5+ "github.com/charmbracelet/catwalk/pkg/catwalk"
5 "github.com/charmbracelet/crush/internal/session"
6 "github.com/charmbracelet/crush/internal/session"
6)
7)
7
8
@@ -16,6 +17,12 @@ type SessionSelectedMsg struct {
16 Session session.Session
17 Session session.Session
17}
18}
18
19
20+// ModelSelectedMsg is a message indicating a model has been selected.
21+type ModelSelectedMsg struct {
22+ Provider catwalk.Provider
23+ Model catwalk.Model
24+}
25+
19// Messages for commands
26// Messages for commands
20type (
27type (
21 SwitchSessionsMsg struct{}
28 SwitchSessionsMsg struct{}
internal/ui/dialog/models.go+13−2
@@ -169,8 +169,19 @@ func (m *Models) Update(msg tea.Msg) tea.Msg {
169 m.list.SelectNext()
169 m.list.SelectNext()
170 m.list.ScrollToSelected()
170 m.list.ScrollToSelected()
171 case key.Matches(msg, m.keyMap.Select):
171 case key.Matches(msg, m.keyMap.Select):
172− if selectedItem := m.list.SelectedItem(); selectedItem != nil {
172+ selectedItem := m.list.SelectedItem()
173− // TODO: Handle model selection confirmation.
173+ if selectedItem == nil {
174+ break
175+ }
176+
177+ modelItem, ok := selectedItem.(*ModelItem)
178+ if !ok {
179+ break
180+ }
181+
182+ return ModelSelectedMsg{
183+ Provider: modelItem.prov,
184+ Model: modelItem.model,
174 }
185 }
175 case key.Matches(msg, m.keyMap.Tab):
186 case key.Matches(msg, m.keyMap.Tab):
176 if m.modelType == ModelTypeLarge {
187 if m.modelType == ModelTypeLarge {
internal/ui/model/ui.go+7
@@ -562,6 +562,13 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
562 m.dialog.CloseDialog(dialog.CommandsID)
562 m.dialog.CloseDialog(dialog.CommandsID)
563 case dialog.QuitMsg:
563 case dialog.QuitMsg:
564 cmds = append(cmds, tea.Quit)
564 cmds = append(cmds, tea.Quit)
565+ case dialog.SwitchModelMsg:
566+ m.dialog.CloseDialog(dialog.CommandsID)
567+ if cmd := m.openModelsDialog(); cmd != nil {
568+ cmds = append(cmds, cmd)
569+ }
570+ case dialog.ModelSelectedMsg:
571+ // TODO: Handle model switching
565 }
572 }
566
573
567 return tea.Batch(cmds...)
574 return tea.Batch(cmds...)