on main help sign in
feat(ui): ctrl+l/ctrl+m to open model switcher (#1274)
5306907Carlos Alexandro Becker
internal/tui/components/dialogs/commands/commands.go+1
@@ -335,6 +335,7 @@ func (c *commandDialogCmp) defaultCommands() []Command {
335 ID: "switch_model",
335 ID: "switch_model",
336 Title: "Switch Model",
336 Title: "Switch Model",
337 Description: "Switch to a different model",
337 Description: "Switch to a different model",
338+ Shortcut: "ctrl+l",
338 Handler: func(cmd Command) tea.Cmd {
339 Handler: func(cmd Command) tea.Cmd {
339 return util.CmdHandler(SwitchModelMsg{})
340 return util.CmdHandler(SwitchModelMsg{})
340 },
341 },
internal/tui/keys.go+5
@@ -9,6 +9,7 @@ type KeyMap struct {
9 Help key.Binding
9 Help key.Binding
10 Commands key.Binding
10 Commands key.Binding
11 Suspend key.Binding
11 Suspend key.Binding
12+ Models key.Binding
12 Sessions key.Binding
13 Sessions key.Binding
13
14
14 pageBindings []key.Binding
15 pageBindings []key.Binding
@@ -32,6 +33,10 @@ func DefaultKeyMap() KeyMap {
32 key.WithKeys("ctrl+z"),
33 key.WithKeys("ctrl+z"),
33 key.WithHelp("ctrl+z", "suspend"),
34 key.WithHelp("ctrl+z", "suspend"),
34 ),
35 ),
36+ Models: key.NewBinding(
37+ key.WithKeys("ctrl+l", "ctrl+m"),
38+ key.WithHelp("ctrl+l", "models"),
39+ ),
35 Sessions: key.NewBinding(
40 Sessions: key.NewBinding(
36 key.WithKeys("ctrl+s"),
41 key.WithKeys("ctrl+s"),
37 key.WithHelp("ctrl+s", "sessions"),
42 key.WithHelp("ctrl+s", "sessions"),
internal/tui/page/chat/chat.go+9−1
@@ -942,11 +942,18 @@ func (p *chatPage) Help() help.KeyMap {
942 key.WithKeys("ctrl+p"),
942 key.WithKeys("ctrl+p"),
943 key.WithHelp("ctrl+p", "commands"),
943 key.WithHelp("ctrl+p", "commands"),
944 )
944 )
945+ modelsBinding := key.NewBinding(
946+ key.WithKeys("ctrl+m", "ctrl+l"),
947+ key.WithHelp("ctrl+l", "models"),
948+ )
949+ if p.keyboardEnhancements.SupportsKeyDisambiguation() {
950+ modelsBinding.SetHelp("ctrl+m", "models")
951+ }
945 helpBinding := key.NewBinding(
952 helpBinding := key.NewBinding(
946 key.WithKeys("ctrl+g"),
953 key.WithKeys("ctrl+g"),
947 key.WithHelp("ctrl+g", "more"),
954 key.WithHelp("ctrl+g", "more"),
948 )
955 )
949− globalBindings = append(globalBindings, commandsBinding)
956+ globalBindings = append(globalBindings, commandsBinding, modelsBinding)
950 globalBindings = append(globalBindings,
957 globalBindings = append(globalBindings,
951 key.NewBinding(
958 key.NewBinding(
952 key.WithKeys("ctrl+s"),
959 key.WithKeys("ctrl+s"),
@@ -963,6 +970,7 @@ func (p *chatPage) Help() help.KeyMap {
963 shortList = append(shortList,
970 shortList = append(shortList,
964 // Commands
971 // Commands
965 commandsBinding,
972 commandsBinding,
973+ modelsBinding,
966 )
974 )
967 fullList = append(fullList, globalBindings)
975 fullList = append(fullList, globalBindings)
968
976
internal/tui/tui.go+17−4
@@ -127,6 +127,9 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127 }
127 }
128 return a, nil
128 return a, nil
129 case tea.KeyboardEnhancementsMsg:
129 case tea.KeyboardEnhancementsMsg:
130+ if msg.SupportsKeyDisambiguation() {
131+ a.keyMap.Models.SetHelp("ctrl+m", "models")
132+ }
130 for id, page := range a.pages {
133 for id, page := range a.pages {
131 m, pageCmd := page.Update(msg)
134 m, pageCmd := page.Update(msg)
132 a.pages[id] = m
135 a.pages[id] = m
@@ -477,6 +480,20 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
477 return util.CmdHandler(dialogs.OpenDialogMsg{
480 return util.CmdHandler(dialogs.OpenDialogMsg{
478 Model: commands.NewCommandDialog(a.selectedSessionID),
481 Model: commands.NewCommandDialog(a.selectedSessionID),
479 })
482 })
483+ case key.Matches(msg, a.keyMap.Models):
484+ // if the app is not configured show no models
485+ if !a.isConfigured {
486+ return nil
487+ }
488+ if a.dialog.ActiveDialogID() == models.ModelsDialogID {
489+ return util.CmdHandler(dialogs.CloseDialogMsg{})
490+ }
491+ if a.dialog.HasDialogs() {
492+ return nil
493+ }
494+ return util.CmdHandler(dialogs.OpenDialogMsg{
495+ Model: models.NewModelDialogCmp(),
496+ })
480 case key.Matches(msg, a.keyMap.Sessions):
497 case key.Matches(msg, a.keyMap.Sessions):
481 // if the app is not configured show no sessions
498 // if the app is not configured show no sessions
482 if !a.isConfigured {
499 if !a.isConfigured {
@@ -489,10 +506,6 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
489 return nil
506 return nil
490 }
507 }
491 var cmds []tea.Cmd
508 var cmds []tea.Cmd
492− if a.dialog.ActiveDialogID() == commands.CommandsDialogID {
493− // If the commands dialog is open, close it first
494− cmds = append(cmds, util.CmdHandler(dialogs.CloseDialogMsg{}))
495− }
496 cmds = append(cmds,
509 cmds = append(cmds,
497 func() tea.Msg {
510 func() tea.Msg {
498 allSessions, _ := a.app.Sessions.List(context.Background())
511 allSessions, _ := a.app.Sessions.List(context.Background())