on main help sign in
fix(ui): dialog sessions refactor and close commands dialog on select
9899424Ayman Bagabas
internal/ui/dialog/commands.go+2−1
@@ -331,7 +331,8 @@ func (c *Commands) defaultCommands() []uicmd.Command {
331 ID: "switch_model",
331 ID: "switch_model",
332 Title: "Switch Model",
332 Title: "Switch Model",
333 Description: "Switch to a different model",
333 Description: "Switch to a different model",
334+ // FIXME: The shortcut might get updated if enhanced keyboard is supported.
334− Shortcut: "ctrl+l",
335+ Shortcut: "ctrl+l",
335 Handler: func(cmd uicmd.Command) tea.Cmd {
336 Handler: func(cmd uicmd.Command) tea.Cmd {
336 return uiutil.CmdHandler(OpenDialogMsg{ModelsID})
337 return uiutil.CmdHandler(OpenDialogMsg{ModelsID})
337 },
338 },
internal/ui/dialog/sessions.go+10−3
@@ -1,11 +1,12 @@
1package dialog
1package dialog
2
2
3import (
3import (
4+ "context"
5+
4 "charm.land/bubbles/v2/help"
6 "charm.land/bubbles/v2/help"
5 "charm.land/bubbles/v2/key"
7 "charm.land/bubbles/v2/key"
6 "charm.land/bubbles/v2/textinput"
8 "charm.land/bubbles/v2/textinput"
7 tea "charm.land/bubbletea/v2"
9 tea "charm.land/bubbletea/v2"
8− "github.com/charmbracelet/crush/internal/session"
9 "github.com/charmbracelet/crush/internal/ui/common"
10 "github.com/charmbracelet/crush/internal/ui/common"
10 "github.com/charmbracelet/crush/internal/ui/list"
11 "github.com/charmbracelet/crush/internal/ui/list"
11)
12)
@@ -32,9 +33,14 @@ type Session struct {
32var _ Dialog = (*Session)(nil)
33var _ Dialog = (*Session)(nil)
33
34
34// NewSessions creates a new Session dialog.
35// NewSessions creates a new Session dialog.
35−func NewSessions(com *common.Common, sessions ...session.Session) *Session {
36+func NewSessions(com *common.Common) (*Session, error) {
36 s := new(Session)
37 s := new(Session)
37 s.com = com
38 s.com = com
39+ sessions, err := com.App.Sessions.List(context.TODO())
40+ if err != nil {
41+ return nil, err
42+ }
43+
38 help := help.New()
44 help := help.New()
39 help.Styles = com.Styles.DialogHelpStyles()
45 help.Styles = com.Styles.DialogHelpStyles()
40
46
@@ -62,7 +68,8 @@ func NewSessions(com *common.Common, sessions ...session.Session) *Session {
62 key.WithHelp("↑", "previous item"),
68 key.WithHelp("↑", "previous item"),
63 )
69 )
64 s.keyMap.Close = CloseKey
70 s.keyMap.Close = CloseKey
71+
65− return s
72+ return s, nil
66}
73}
67
74
68// SetSize sets the size of the dialog.
75// SetSize sets the size of the dialog.
internal/ui/model/ui.go+2−3
@@ -540,7 +540,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
540 break
540 break
541 }
541 }
542
542
543− m.dialog.CloseDialog(msg.DialogID)
543+ m.dialog.CloseDialog(dialog.CommandsID)
544
544
545 // Command dialog messages
545 // Command dialog messages
546 case dialog.ToggleYoloModeMsg:
546 case dialog.ToggleYoloModeMsg:
@@ -1436,12 +1436,11 @@ func (m *UI) openSessionsDialog() tea.Cmd {
1436 return nil
1436 return nil
1437 }
1437 }
1438
1438
1439− sessions, err := m.com.App.Sessions.List(context.TODO())
1439+ dialog, err := dialog.NewSessions(m.com)
1440 if err != nil {
1440 if err != nil {
1441 return uiutil.ReportError(err)
1441 return uiutil.ReportError(err)
1442 }
1442 }
1443
1443
1444− dialog := dialog.NewSessions(m.com, sessions...)
1445 // TODO: Get. Rid. Of. Magic numbers!
1444 // TODO: Get. Rid. Of. Magic numbers!
1446 dialog.SetSize(min(120, m.width-8), 30)
1445 dialog.SetSize(min(120, m.width-8), 30)
1447 m.dialog.OpenDialog(dialog)
1446 m.dialog.OpenDialog(dialog)