mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
slash commands (#2157)
Co-authored-by: adamdotdevin <2363879+adamdottv@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user