about summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 1d45696..8307bd0 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -39,6 +39,12 @@ type Aerc struct {
 	getpasswd   *GetPasswd
 }
 
+type Choice struct {
+	Key     string
+	Text    string
+	Command []string
+}
+
 func NewAerc(conf *config.AercConfig, logger *log.Logger,
 	cmd func(cmd []string) error, complete func(cmd string) []string,
 	cmdHistory lib.History) *Aerc {
@@ -444,6 +450,33 @@ func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) {
 	aerc.prompts.Push(p)
 }
 
+func (aerc *Aerc) RegisterChoices(choices []Choice) {
+	cmds := make(map[string][]string)
+	texts := []string{}
+	for _, c := range choices {
+		text := fmt.Sprintf("[%s] %s", c.Key, c.Text)
+		if strings.Contains(c.Text, c.Key) {
+			text = strings.Replace(c.Text, c.Key, "[" + c.Key + "]", 1)
+		}
+		texts = append(texts, text)
+		cmds[c.Key] = c.Command
+	}
+	prompt := strings.Join(texts, ", ") + "? "
+	p := NewPrompt(aerc.conf, prompt, func(text string) {
+		cmd, ok := cmds[text]
+		if !ok {
+			return
+		}
+		err := aerc.cmd(cmd)
+		if err != nil {
+			aerc.PushError(" " + err.Error())
+		}
+	}, func(cmd string) []string {
+		return nil // TODO: completions
+	})
+	aerc.prompts.Push(p)
+}
+
 func (aerc *Aerc) Mailto(addr *url.URL) error {
 	acct := aerc.SelectedAccount()
 	if acct == nil {