From 28f4f2151667020b37da1650ce09efb743b4308c Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Mon, 28 Jul 2025 22:07:15 +0200 Subject: [PATCH] chore: add more commands --- .../components/dialogs/commands/commands.go | 66 ++++++++++++++----- internal/tui/page/chat/chat.go | 5 +- internal/tui/tui.go | 11 +++- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/internal/tui/components/dialogs/commands/commands.go b/internal/tui/components/dialogs/commands/commands.go index 50a67b77be373f987849953d0d60d9773caeb752..713c8628e7d962a6bce06b43c7e6ebd07b5bedaf 100644 --- a/internal/tui/components/dialogs/commands/commands.go +++ b/internal/tui/components/dialogs/commands/commands.go @@ -60,6 +60,9 @@ type commandDialogCmp struct { type ( SwitchSessionsMsg struct{} SwitchModelMsg struct{} + QuitMsg struct{} + OpenFilePickerMsg struct{} + ToggleHelpMsg struct{} ToggleCompactModeMsg struct{} ToggleThinkingMsg struct{} CompactMsg struct { @@ -248,13 +251,20 @@ func (c *commandDialogCmp) Position() (int, int) { func (c *commandDialogCmp) defaultCommands() []Command { commands := []Command{ { - ID: "init", - Title: "Initialize Project", - Description: "Create/Update the CRUSH.md memory file", + ID: "switch_session", + Title: "Switch Session", + Description: "Switch to a different session", + Shortcut: "ctrl+s", Handler: func(cmd Command) tea.Cmd { - return util.CmdHandler(chat.SendMsg{ - Text: prompt.Initialize(), - }) + return util.CmdHandler(SwitchSessionsMsg{}) + }, + }, + { + ID: "switch_model", + Title: "Switch Model", + Description: "Switch to a different model", + Handler: func(cmd Command) tea.Cmd { + return util.CmdHandler(SwitchModelMsg{}) }, }, } @@ -307,23 +317,49 @@ func (c *commandDialogCmp) defaultCommands() []Command { }, }) } + if c.sessionID != "" { + agentCfg := config.Get().Agents["coder"] + model := config.Get().GetModelByType(agentCfg.Model) + if model.SupportsImages { + commands = append(commands, Command{ + ID: "file_picker", + Title: "Open File Picker", + Shortcut: "ctrl+f", + Description: "Open file picker", + Handler: func(cmd Command) tea.Cmd { + return util.CmdHandler(OpenFilePickerMsg{}) + }, + }) + } + } return append(commands, []Command{ { - ID: "switch_session", - Title: "Switch Session", - Description: "Switch to a different session", - Shortcut: "ctrl+s", + ID: "toggle_help", + Title: "Toggle Help", + Shortcut: "ctrl+g", + Description: "Toggle help", Handler: func(cmd Command) tea.Cmd { - return util.CmdHandler(SwitchSessionsMsg{}) + return util.CmdHandler(ToggleHelpMsg{}) }, }, { - ID: "switch_model", - Title: "Switch Model", - Description: "Switch to a different model", + ID: "init", + Title: "Initialize Project", + Description: "Create/Update the CRUSH.md memory file", Handler: func(cmd Command) tea.Cmd { - return util.CmdHandler(SwitchModelMsg{}) + return util.CmdHandler(chat.SendMsg{ + Text: prompt.Initialize(), + }) + }, + }, + { + ID: "quit", + Title: "Quit", + Description: "Quit", + Shortcut: "ctrl+c", + Handler: func(cmd Command) tea.Cmd { + return util.CmdHandler(QuitMsg{}) }, }, }...) diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index 4b4495709d6359919b8525af73b6fcb1a09db330..9f79da4bcf42f0eef5f73155a65d5ac7ca70b22c 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -37,8 +37,7 @@ import ( var ChatPageID page.PageID = "chat" type ( - OpenFilePickerMsg struct{} - ChatFocusedMsg struct { + ChatFocusedMsg struct { Focused bool } CancelTimerExpiredMsg struct{} @@ -299,7 +298,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { agentCfg := config.Get().Agents["coder"] model := config.Get().GetModelByType(agentCfg.Model) if model.SupportsImages { - return p, util.CmdHandler(OpenFilePickerMsg{}) + return p, util.CmdHandler(commands.OpenFilePickerMsg{}) } else { return p, util.ReportWarn("File attachments are not supported by the current model: " + model.Name) } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 7bcbdaae5051620756594db7d8f38e757111b1cb..b96fe26c9f80d565fa58b9228edee89d013117da 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -170,7 +170,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, util.CmdHandler(dialogs.OpenDialogMsg{ Model: compact.NewCompactDialogCmp(a.app.CoderAgent, msg.SessionID, true), }) - + case commands.QuitMsg: + return a, util.CmdHandler(dialogs.OpenDialogMsg{ + Model: quit.NewQuitDialog(), + }) + case commands.ToggleHelpMsg: + a.status.ToggleFullHelp() + a.showingFullHelp = !a.showingFullHelp + return a, a.handleWindowResize(a.wWidth, a.wHeight) // Model Switch case models.ModelSelectedMsg: config.Get().UpdatePreferredModel(msg.ModelType, msg.Model) @@ -187,7 +194,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, util.ReportInfo(fmt.Sprintf("%s model changed to %s", modelTypeName, msg.Model.Model)) // File Picker - case chat.OpenFilePickerMsg: + case commands.OpenFilePickerMsg: if a.dialog.ActiveDialogID() == filepicker.FilePickerID { // If the commands dialog is already open, close it return a, util.CmdHandler(dialogs.CloseDialogMsg{})