+ case tcell.KeyTab:
+ args := SplitCommandArgs(m.response)
+ currentArgNum := len(args) - 1
+ currentArg := args[currentArgNum]
+ var completionType Completion
+
+ if completionTypes[0] == CommandCompletion && currentArgNum > 0 {
+ if command, ok := commands[args[0]]; ok {
+ completionTypes = append([]Completion{CommandCompletion}, command.completions...)
+ }
+ }
+
+ if currentArgNum >= len(completionTypes) {
+ completionType = completionTypes[len(completionTypes)-1]
+ } else {
+ completionType = completionTypes[currentArgNum]
+ }
+
+ var chosen string
+ if completionType == FileCompletion {
+ chosen, suggestions = FileComplete(currentArg)
+ } else if completionType == CommandCompletion {
+ chosen, suggestions = CommandComplete(currentArg)
+ } else if completionType == HelpCompletion {
+ chosen, suggestions = HelpComplete(currentArg)
+ } else if completionType == OptionCompletion {
+ chosen, suggestions = OptionComplete(currentArg)
+ } else if completionType == PluginCmdCompletion {
+ chosen, suggestions = PluginCmdComplete(currentArg)
+ } else if completionType == PluginNameCompletion {
+ chosen, suggestions = PluginNameComplete(currentArg)
+ } else if completionType < NoCompletion {
+ chosen, suggestions = PluginComplete(completionType, currentArg)
+ }
+
+ if len(suggestions) > 1 {
+ chosen = chosen + CommonSubstring(suggestions...)
+ }
+
+ if chosen != "" {
+ m.response = JoinCommandArgs(append(args[:len(args)-1], chosen)...)
+ m.cursorx = Count(m.response)
+ }