aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-10-12 00:21:44 +0200
committerRobin Jarry <robin@jarry.cc>2024-10-23 10:22:51 +0200
commit3c9ad93801ce9bb71d76fa398d7d94f1afd2c2cb (patch)
treedcc715e090fedf65e2b0f800d4d969b4606f7a5c /commands
parent63db443949b92eed5f5d2ded5f430bda96312b43 (diff)
downloadaerc-3c9ad93801ce9bb71d76fa398d7d94f1afd2c2cb.tar.gz
completion: display descriptions next to choices
Use go-opt v2 new completion API which returns items descriptions along with their text values. Display the descriptions after the items separated by two spaces. Wrap the descriptions in parentheses to better indicate that they are not part of the completion choices. Limit the description length to 80 characters to avoid display issues. Add a new style object completion_description in stylesets. By default, the object will be rendered with a dimmed terminal attribute. Update all stylesets and documentation accordingly. Implements: https://todo.sr.ht/~rjarry/aerc/271 Link: https://git.sr.ht/~rjarry/go-opt/commit/ebeb82538395a Changelog-added: Command completion now displays descriptions next to completion items. Changelog-added: New `completion_description` style object in style sets used for rendering completion item descriptions. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bojan Gabric <bojan@bojangabric.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/cf.go2
-rw-r--r--commands/account/mkdir.go2
-rw-r--r--commands/account/rmdir.go2
-rw-r--r--commands/commands.go4
-rw-r--r--commands/completion_helpers.go2
-rw-r--r--commands/compose/send.go10
-rw-r--r--commands/menu.go2
-rw-r--r--commands/patch/find.go2
-rw-r--r--commands/patch/list.go2
-rw-r--r--commands/patch/patch.go8
-rw-r--r--commands/prompt.go2
-rw-r--r--commands/util.go2
12 files changed, 23 insertions, 17 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go
index 8d7d27ae..2c2cee53 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -10,7 +10,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
type ChangeFolder struct {
diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go
index 13310665..d6a6f9f3 100644
--- a/commands/account/mkdir.go
+++ b/commands/account/mkdir.go
@@ -7,7 +7,7 @@ import (
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/worker/types"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
type MakeDir struct {
diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go
index ff1463b6..3c5b24d7 100644
--- a/commands/account/rmdir.go
+++ b/commands/account/rmdir.go
@@ -9,7 +9,7 @@ import (
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
type RemoveDir struct {
diff --git a/commands/commands.go b/commands/commands.go
index 27e50bcf..e87cd802 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -9,7 +9,7 @@ import (
"strings"
"unicode"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/config"
@@ -272,7 +272,7 @@ func GetTemplateCompletion(
// GetCompletions returns the completion options and the command prefix
func GetCompletions(
cmd Command, args *opt.Args,
-) (options []string, prefix string) {
+) (options []opt.Completion, prefix string) {
// copy zeroed struct
tmp := reflect.New(reflect.TypeOf(cmd)).Interface().(Command)
s, err := args.ArgSafe(0)
diff --git a/commands/completion_helpers.go b/commands/completion_helpers.go
index 92c33bea..8d293a32 100644
--- a/commands/completion_helpers.go
+++ b/commands/completion_helpers.go
@@ -32,7 +32,7 @@ func GetAddress(search string) []string {
if cmpl != nil {
addrList, _ := cmpl.ForHeader("to")(search)
for _, full := range addrList {
- addr, err := mail.ParseAddress(full)
+ addr, err := mail.ParseAddress(full.Value)
if err != nil {
continue
}
diff --git a/commands/compose/send.go b/commands/compose/send.go
index aefeaa3c..1e30bd0e 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -19,6 +19,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/send"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
+ "git.sr.ht/~rjarry/go-opt/v2"
"github.com/emersion/go-message/mail"
)
@@ -142,12 +143,13 @@ func (s Send) Execute(args []string) error {
from, rcpts, tab.Name, s.CopyTo,
s.Archive, copyToReplied)
}
- }, func(cmd string) ([]string, string) {
+ }, func(cmd string) ([]opt.Completion, string) {
+ var comps []opt.Completion
if cmd == "" {
- return []string{"y", "n"}, ""
+ comps = append(comps, opt.Completion{Value: "y"})
+ comps = append(comps, opt.Completion{Value: "n"})
}
-
- return nil, ""
+ return comps, ""
},
)
diff --git a/commands/menu.go b/commands/menu.go
index 6ebba81f..08eec9cb 100644
--- a/commands/menu.go
+++ b/commands/menu.go
@@ -12,7 +12,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/log"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
type Menu struct {
diff --git a/commands/patch/find.go b/commands/patch/find.go
index a508551d..10b96ef2 100644
--- a/commands/patch/find.go
+++ b/commands/patch/find.go
@@ -11,7 +11,7 @@ import (
"git.sr.ht/~rjarry/aerc/commands/account"
"git.sr.ht/~rjarry/aerc/lib/pama"
"git.sr.ht/~rjarry/aerc/lib/pama/models"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
type Find struct {
diff --git a/commands/patch/list.go b/commands/patch/list.go
index 0451605b..b05a9bf3 100644
--- a/commands/patch/list.go
+++ b/commands/patch/list.go
@@ -13,7 +13,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/pama"
"git.sr.ht/~rjarry/aerc/lib/pama/models"
"git.sr.ht/~rjarry/aerc/lib/ui"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
"git.sr.ht/~rockorager/vaxis"
)
diff --git a/commands/patch/patch.go b/commands/patch/patch.go
index 25d7850a..15fb35f4 100644
--- a/commands/patch/patch.go
+++ b/commands/patch/patch.go
@@ -5,7 +5,7 @@ import (
"fmt"
"git.sr.ht/~rjarry/aerc/commands"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
)
var subCommands map[string]commands.Command
@@ -68,7 +68,11 @@ func (p *Patch) CompleteSubArgs(arg string) []string {
}
// prepend arbitrary string to arg to work with sub-commands
options, _ := commands.GetCompletions(p.SubCmd, opt.LexArgs("a "+arg))
- return options
+ completions := make([]string, 0, len(options))
+ for _, o := range options {
+ completions = append(completions, o.Value)
+ }
+ return completions
}
func (p Patch) Execute(args []string) error {
diff --git a/commands/prompt.go b/commands/prompt.go
index 9ab2aac1..fe6632e9 100644
--- a/commands/prompt.go
+++ b/commands/prompt.go
@@ -1,7 +1,7 @@
package commands
import (
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
"git.sr.ht/~rjarry/aerc/app"
)
diff --git a/commands/util.go b/commands/util.go
index bb20a204..8c1e497d 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -18,7 +18,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
- "git.sr.ht/~rjarry/go-opt"
+ "git.sr.ht/~rjarry/go-opt/v2"
"git.sr.ht/~rockorager/vaxis"
)