diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-30 21:05:56 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-02 11:59:39 +0100 |
commit | 2dfeb7130a8fb97d927a55efa738f110f46cb688 (patch) | |
tree | cca6a06999d2be32f01e4ac6ae2998c5f24c2895 /commands/util.go | |
parent | faa879f9a84d44f9b251410fc923a827a44df1a7 (diff) | |
download | aerc-2dfeb7130a8fb97d927a55efa738f110f46cb688.tar.gz |
completion: refactor filter list api
Remove CompletionFromList which is a trivial wrapper around FilterList.
Remove the prefix, suffix and isFuzzy arguments from FilterList.
Replace prefix, suffix by an optional callback to allow post processing
of completion results before presenting them to the user.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/util.go')
-rw-r--r-- | commands/util.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/commands/util.go b/commands/util.go index 726669af..c2c530da 100644 --- a/commands/util.go +++ b/commands/util.go @@ -228,18 +228,29 @@ func MsgInfoFromUids(store *lib.MessageStore, uids []uint32, statusInfo func(str return infos, nil } +func QuoteSpace(s string) string { + return opt.QuoteArg(s) + " " +} + // 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, suffix string, isFuzzy bool) []string { +// by case smart prefix, or by fuzzy matching +// An optional post processing function can be passed to prepend, append or +// quote each value. +func FilterList( + valid []string, search string, postProc func(string) string, +) []string { + if postProc == nil { + postProc = opt.QuoteArg + } out := make([]string, 0, len(valid)) - if isFuzzy { + if app.SelectedAccountUiConfig().FuzzyComplete { for _, v := range fuzzy.RankFindFold(search, valid) { - out = append(out, opt.QuoteArg(prefix+v.Target)+suffix) + out = append(out, postProc(v.Target)) } } else { for _, v := range valid { if hasCaseSmartPrefix(v, search) { - out = append(out, opt.QuoteArg(prefix+v)+suffix) + out = append(out, postProc(v)) } } } |