From 2dfeb7130a8fb97d927a55efa738f110f46cb688 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 30 Oct 2023 21:05:56 +0100 Subject: 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 Tested-by: Inwit --- commands/account/mkdir.go | 10 +++++++--- commands/account/recover.go | 2 +- commands/account/search.go | 6 +++--- commands/account/sort.go | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'commands/account') diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go index 3e546ace..af3d1045 100644 --- a/commands/account/mkdir.go +++ b/commands/account/mkdir.go @@ -7,6 +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" ) type MakeDir struct { @@ -26,10 +27,13 @@ func (*MakeDir) CompleteFolder(arg string) []string { if acct == nil { return nil } + sep := app.SelectedAccount().Worker().PathSeparator() return commands.FilterList( - acct.Directories().List(), arg, "", - app.SelectedAccount().Worker().PathSeparator(), - app.SelectedAccountUiConfig().FuzzyComplete) + acct.Directories().List(), arg, + func(s string) string { + return opt.QuoteArg(s) + sep + }, + ) } func (m MakeDir) Execute(args []string) error { diff --git a/commands/account/recover.go b/commands/account/recover.go index cba6e0cb..a2170edd 100644 --- a/commands/account/recover.go +++ b/commands/account/recover.go @@ -39,7 +39,7 @@ func (*Recover) CompleteFile(arg string) []string { if err != nil { return nil } - return commands.CompletionFromList(files, arg) + return commands.FilterList(files, arg, nil) } func (r Recover) Execute(args []string) error { diff --git a/commands/account/search.go b/commands/account/search.go index ca1b9684..10481e8e 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -42,15 +42,15 @@ func (SearchFilter) Aliases() []string { } func (*SearchFilter) CompleteFlag(arg string) []string { - return commands.CompletionFromList(commands.GetFlagList(), arg) + return commands.FilterList(commands.GetFlagList(), arg, commands.QuoteSpace) } func (*SearchFilter) CompleteAddress(arg string) []string { - return commands.CompletionFromList(commands.GetAddress(arg), arg) + return commands.FilterList(commands.GetAddress(arg), arg, commands.QuoteSpace) } func (*SearchFilter) CompleteDate(arg string) []string { - return commands.CompletionFromList(commands.GetDateList(), arg) + return commands.FilterList(commands.GetDateList(), arg, commands.QuoteSpace) } func (s *SearchFilter) ParseRead(arg string) error { diff --git a/commands/account/sort.go b/commands/account/sort.go index ccccab25..3103a388 100644 --- a/commands/account/sort.go +++ b/commands/account/sort.go @@ -38,7 +38,7 @@ var supportedCriteria = []string{ } func (*Sort) CompleteCriteria(arg string) []string { - return commands.CompletionFromList(supportedCriteria, arg) + return commands.FilterList(supportedCriteria, arg, commands.QuoteSpace) } func (Sort) Execute(args []string) error { -- cgit