| 1 |
package commands |
| 2 |
|
| 3 |
import ( |
| 4 |
"git.sr.ht/~rjarry/go-opt/v2" |
| 5 |
|
| 6 |
"git.sr.ht/~rjarry/aerc/app" |
| 7 |
) |
| 8 |
|
| 9 |
type Prompt struct { |
| 10 |
Text string `opt:"text"` |
| 11 |
Cmd []string `opt:"..." complete:"CompleteCommand" desc:"Command name."` |
| 12 |
} |
| 13 |
|
| 14 |
func init() { |
| 15 |
Register(Prompt{}) |
| 16 |
} |
| 17 |
|
| 18 |
func (Prompt) Description() string { |
| 19 |
return "Prompt for user input and execute a command." |
| 20 |
} |
| 21 |
|
| 22 |
func (Prompt) Context() CommandContext { |
| 23 |
return GLOBAL |
| 24 |
} |
| 25 |
|
| 26 |
func (Prompt) Aliases() []string { |
| 27 |
return []string{"prompt"} |
| 28 |
} |
| 29 |
|
| 30 |
func (*Prompt) CompleteCommand(arg string) []string { |
| 31 |
return FilterList(ActiveCommandNames(), arg, nil) |
| 32 |
} |
| 33 |
|
| 34 |
func (p Prompt) Execute(args []string) error { |
| 35 |
cmd := opt.QuoteArgs(p.Cmd...) |
| 36 |
app.RegisterPrompt(p.Text, cmd.String()) |
| 37 |
return nil |
| 38 |
} |