From 133fe41cd5fb0ec3dc03a90e58526408297878fd Mon Sep 17 00:00:00 2001 From: Dax Date: Fri, 22 Aug 2025 17:04:28 -0400 Subject: slash commands (#2157) Co-authored-by: adamdotdevin <2363879+adamdottv@users.noreply.github.com> --- packages/tui/internal/commands/command.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'packages/tui/internal/commands') diff --git a/packages/tui/internal/commands/command.go b/packages/tui/internal/commands/command.go index bd5d61b95..3a5287ca3 100644 --- a/packages/tui/internal/commands/command.go +++ b/packages/tui/internal/commands/command.go @@ -31,6 +31,7 @@ type Command struct { Description string Keybindings []Keybinding Trigger []string + Custom bool } func (c Command) Keys() []string { @@ -96,6 +97,7 @@ func (r CommandRegistry) Sorted() []Command { }) return commands } + func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command { var matched []Command for _, command := range r.Sorted() { @@ -182,7 +184,7 @@ func parseBindings(bindings ...string) []Keybinding { return parsedBindings } -func LoadFromConfig(config *opencode.Config) CommandRegistry { +func LoadFromConfig(config *opencode.Config, customCommands []opencode.Command) CommandRegistry { defaults := []Command{ { Name: AppHelpCommand, @@ -400,6 +402,16 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry { } registry[command.Name] = command } + for _, command := range customCommands { + registry[CommandName(command.Name)] = Command{ + Name: CommandName(command.Name), + Description: command.Description, + Trigger: []string{command.Name}, + Keybindings: []Keybinding{}, + Custom: true, + } + } + slog.Info("Loaded commands", "commands", registry) return registry } -- cgit v1.2.3