diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-22 23:23:18 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-28 19:25:10 +0200 |
commit | abe228b14d97d8d47e8ff4406de387fac45cfe68 (patch) | |
tree | 56117403d1ae32d7253f86bab01a944a3cf225b9 /commands/util.go | |
parent | 30851656591293ed2e19340ab78c937855a11143 (diff) | |
download | aerc-abe228b14d97d8d47e8ff4406de387fac45cfe68.tar.gz |
commands: use completion from go-opt
Implement command completion with complete struct field tags from the
get-opt library introduced earlier.
Changelog-changed: Improved command completion.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/util.go')
-rw-r--r-- | commands/util.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/commands/util.go b/commands/util.go index e9a377a6..a9aa81b3 100644 --- a/commands/util.go +++ b/commands/util.go @@ -18,6 +18,7 @@ import ( "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" + "git.sr.ht/~rjarry/go-opt" "github.com/gdamore/tcell/v2" ) @@ -93,7 +94,7 @@ func CompletePath(path string) []string { } if !strings.HasPrefix(path, ".") && !strings.Contains(path, "/.") { - log.Debugf("removing hidden files from glob results") + log.Tracef("removing hidden files from glob results") for i := len(matches) - 1; i >= 0; i-- { if strings.HasPrefix(filepath.Base(matches[i]), ".") { if i == len(matches)-1 { @@ -107,11 +108,13 @@ func CompletePath(path string) []string { for i, m := range matches { if isDir(m) { - matches[i] = m + "/" + m += "/" } + matches[i] = opt.QuoteArg((xdg.TildeHome(m))) } sort.Strings(matches) + return matches } @@ -122,11 +125,11 @@ func CompletePath(path string) []string { if isDir(f) { f += "/" } - - files[i] = f + files[i] = opt.QuoteArg((xdg.TildeHome(f))) } sort.Strings(files) + return files } @@ -227,16 +230,16 @@ func MsgInfoFromUids(store *lib.MessageStore, uids []uint32, statusInfo func(str // FilterList takes a list of valid completions and filters it, either // by case smart prefix, or by fuzzy matching, prepending "prefix" to each completion -func FilterList(valid []string, search, prefix string, isFuzzy bool) []string { - out := make([]string, 0) +func FilterList(valid []string, search, prefix, suffix string, isFuzzy bool) []string { + out := make([]string, 0, len(valid)) if isFuzzy { for _, v := range fuzzy.RankFindFold(search, valid) { - out = append(out, prefix+v.Target) + out = append(out, opt.QuoteArg(prefix+v.Target+suffix)) } } else { for _, v := range valid { if hasCaseSmartPrefix(v, search) { - out = append(out, prefix+v) + out = append(out, opt.QuoteArg(prefix+v+suffix)) } } } |