diff --git a/internal/tui/components/dialogs/commands/arguments.go b/internal/tui/components/dialogs/commands/arguments.go index d00d10be1f835ce78c83d337632ae20a47fbfedd..0f46895a24ea5340d8496f00c9cf988f39d73a91 100644 --- a/internal/tui/components/dialogs/commands/arguments.go +++ b/internal/tui/components/dialogs/commands/arguments.go @@ -21,8 +21,8 @@ const ( type ShowArgumentsDialogMsg struct { CommandID string Description string - Content string ArgNames []string + OnSubmit func(args map[string]string) tea.Cmd } // CloseArgumentsDialogMsg is a message that is sent when the arguments dialog is closed. diff --git a/internal/tui/components/dialogs/commands/loader.go b/internal/tui/components/dialogs/commands/loader.go index 774888bcb91f3a0e9dab82c3e9dd7f7a134306f9..391350768806b6da06ffebd9a4f7c02b0bb96a0f 100644 --- a/internal/tui/components/dialogs/commands/loader.go +++ b/internal/tui/components/dialogs/commands/loader.go @@ -160,18 +160,31 @@ func createCommandHandler(id, desc, content string) func(Command) tea.Cmd { return func(cmd Command) tea.Cmd { args := extractArgNames(content) - if len(args) > 0 { - return util.CmdHandler(ShowArgumentsDialogMsg{ - CommandID: id, - Description: desc, - Content: content, - ArgNames: args, + if len(args) == 0 { + return util.CmdHandler(CommandRunCustomMsg{ + Content: content, }) } + return util.CmdHandler(ShowArgumentsDialogMsg{ + CommandID: id, + Description: desc, + ArgNames: args, + OnSubmit: func(args map[string]string) tea.Cmd { + return execUserPrompt(content, args) + }, + }) + } +} - return util.CmdHandler(CommandRunCustomMsg{ +func execUserPrompt(content string, args map[string]string) tea.Cmd { + return func() tea.Msg { + for name, value := range args { + placeholder := "$" + name + content = strings.ReplaceAll(content, placeholder, value) + } + return CommandRunCustomMsg{ Content: content, - }) + } } } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index e0e5ad64b3054223c9b110385950a7ca4b87e701..8cd754fc1f8999bcc8db98f333d2d4790e3b99ff 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -156,19 +156,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { msg.CommandID, msg.Description, args, - func(args map[string]string) tea.Cmd { - return func() tea.Msg { - content := msg.Content - for _, name := range msg.ArgNames { - value := args[name] - placeholder := "$" + name - content = strings.ReplaceAll(content, placeholder, value) - } - return commands.CommandRunCustomMsg{ - Content: content, - } - } - }, + msg.OnSubmit, ), }, )