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 {
previous revision' href='/akkartik/mu/blame/mu.vim?h=hlt&id=ad8e984fd4590740cb6dc23e951848108f671aac'>^
b38d7fff ^
a6d9bd9b ^


e3894819 ^
b38d7fff ^
a6d9bd9b ^



1ae4e0d9 ^
a6d9bd9b ^
31a9d39e ^

a6d9bd9b ^
2e534c0e ^
1ae4e0d9 ^
b94f150a ^
1ae4e0d9 ^
fbf0536d ^


fbf0536d ^
10f49c64 ^
b38d7fff ^
e3894819 ^
1ae4e0d9 ^
fc2046a1 ^
1ead3562 ^
38f0b91a ^
1ead3562 ^
70f70118 ^
04afb4b0 ^
426009da ^
b38d7fff ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68