Change summary
internal/ui/dialog/commands.go | 3 ++-
internal/ui/dialog/sessions.go | 13 ++++++++++---
internal/ui/model/ui.go | 5 ++---
3 files changed, 14 insertions(+), 7 deletions(-)
Detailed changes
@@ -331,7 +331,8 @@ func (c *Commands) defaultCommands() []uicmd.Command {
ID: "switch_model",
Title: "Switch Model",
Description: "Switch to a different model",
- Shortcut: "ctrl+l",
+ // FIXME: The shortcut might get updated if enhanced keyboard is supported.
+ Shortcut: "ctrl+l",
Handler: func(cmd uicmd.Command) tea.Cmd {
return uiutil.CmdHandler(OpenDialogMsg{ModelsID})
},
@@ -1,11 +1,12 @@
package dialog
import (
+ "context"
+
"charm.land/bubbles/v2/help"
"charm.land/bubbles/v2/key"
"charm.land/bubbles/v2/textinput"
tea "charm.land/bubbletea/v2"
- "github.com/charmbracelet/crush/internal/session"
"github.com/charmbracelet/crush/internal/ui/common"
"github.com/charmbracelet/crush/internal/ui/list"
)
@@ -32,9 +33,14 @@ type Session struct {
var _ Dialog = (*Session)(nil)
// NewSessions creates a new Session dialog.
-func NewSessions(com *common.Common, sessions ...session.Session) *Session {
+func NewSessions(com *common.Common) (*Session, error) {
s := new(Session)
s.com = com
+ sessions, err := com.App.Sessions.List(context.TODO())
+ if err != nil {
+ return nil, err
+ }
+
help := help.New()
help.Styles = com.Styles.DialogHelpStyles()
@@ -62,7 +68,8 @@ func NewSessions(com *common.Common, sessions ...session.Session) *Session {
key.WithHelp("↑", "previous item"),
)
s.keyMap.Close = CloseKey
- return s
+
+ return s, nil
}
// SetSize sets the size of the dialog.
@@ -540,7 +540,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
break
}
- m.dialog.CloseDialog(msg.DialogID)
+ m.dialog.CloseDialog(dialog.CommandsID)
// Command dialog messages
case dialog.ToggleYoloModeMsg:
@@ -1436,12 +1436,11 @@ func (m *UI) openSessionsDialog() tea.Cmd {
return nil
}
- sessions, err := m.com.App.Sessions.List(context.TODO())
+ dialog, err := dialog.NewSessions(m.com)
if err != nil {
return uiutil.ReportError(err)
}
- dialog := dialog.NewSessions(m.com, sessions...)
// TODO: Get. Rid. Of. Magic numbers!
dialog.SetSize(min(120, m.width-8), 30)
m.dialog.OpenDialog(dialog)