From 12e8217d1fa0f4c4c83eebcc7473ecb8f0c072ba Mon Sep 17 00:00:00 2001 From: Sergey Smirnykh Date: Sat, 2 Jul 2022 08:45:54 +0700 Subject: commands: implement prompt completion This patch implements :prompt completion. The completion mechanism only provides completions when there is at least one argument specified (prompt text). The mechanism is based on other commands' completions and works as follows: 1. Attempts to look up a command by the name specified in args[1]. 2.a On success it uses command.Complete. 2.b Otherwise, if total arguments count is lesser or equals than 2 (i.e. no command arguments specified), it attempts to complete the command's name. Additional effort is made to preserve prompt text, which often contains spaces and formatting. Signed-off-by: Sergey Smirnykh Acked-by: Robin Jarry --- commands/commands.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'commands/commands.go') diff --git a/commands/commands.go b/commands/commands.go index 2753686f..1aa8e1af 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -37,6 +37,13 @@ func (cmds *Commands) Names() []string { return names } +func (cmds *Commands) ByName(name string) Command { + if cmd, ok := cmds.dict()[name]; ok { + return cmd + } + return nil +} + func (cmds *Commands) Register(cmd Command) { // TODO enforce unique aliases, until then, duplicate each if len(cmd.Aliases()) < 1 { -- cgit