diff options
| author | Dax <[email protected]> | 2025-08-22 17:04:28 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-22 17:04:28 -0400 |
| commit | 133fe41cd5fb0ec3dc03a90e58526408297878fd (patch) | |
| tree | 82aac357a61fe9e7a6802974f6c7cf169a9f22a8 /packages/tui/internal/components/chat | |
| parent | 74c1085103e130cb07522e3ad725f17eca3e5832 (diff) | |
| download | opencode-133fe41cd5fb0ec3dc03a90e58526408297878fd.tar.gz opencode-133fe41cd5fb0ec3dc03a90e58526408297878fd.zip | |
slash commands (#2157)
Co-authored-by: adamdotdevin <[email protected]>
Diffstat (limited to 'packages/tui/internal/components/chat')
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 28 | ||||
| -rw-r--r-- | packages/tui/internal/components/chat/messages.go | 4 |
2 files changed, 31 insertions, 1 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index c5ecdc21d..0c52ca84c 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -224,10 +224,17 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case dialog.CompletionSelectedMsg: switch msg.Item.ProviderID { case "commands": - commandName := strings.TrimPrefix(msg.Item.Value, "/") + command := msg.Item.RawData.(commands.Command) + if command.Custom { + m.SetValue("/" + command.PrimaryTrigger() + " ") + return m, nil + } + updated, cmd := m.Clear() m = updated.(*editorComponent) cmds = append(cmds, cmd) + + commandName := strings.TrimPrefix(msg.Item.Value, "/") cmds = append(cmds, util.CmdHandler(commands.ExecuteCommandMsg(m.app.Commands[commands.CommandName(commandName)]))) return m, tea.Batch(cmds...) case "files": @@ -481,6 +488,25 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { } var cmds []tea.Cmd + if strings.HasPrefix(value, "/") { + value = value[1:] + commandName := strings.Split(value, " ")[0] + command := m.app.Commands[commands.CommandName(commandName)] + if command.Custom { + args := strings.TrimPrefix(value, command.PrimaryTrigger()+" ") + cmds = append( + cmds, + util.CmdHandler(app.SendCommand{Command: string(command.Name), Args: args}), + ) + + updated, cmd := m.Clear() + m = updated.(*editorComponent) + cmds = append(cmds, cmd) + + return m, tea.Batch(cmds...) + } + } + attachments := m.textarea.GetAttachments() prompt := app.Prompt{Text: value, Attachments: attachments} diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.go index 97c529721..a299d65af 100644 --- a/packages/tui/internal/components/chat/messages.go +++ b/packages/tui/internal/components/chat/messages.go @@ -174,6 +174,10 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.GotoBottom() m.tail = true return m, nil + case app.SendCommand: + m.viewport.GotoBottom() + m.tail = true + return m, nil case dialog.ThemeSelectedMsg: m.cache.Clear() m.loading = true |
