shell.setCompletionFunction
Function shell.setCompletionFunction | |
Added by ComputerCraft 1.74, shell.setCompletionFunction() associates a "completion function" with a given path. When a user enters that path into the shell's command line, the assigned function will be used to provide suggestions for tab completion (which can be based on the number of parameters entered so far, and what the previous ones were). For example, if the user enters "pastebin ", a suitable tab completion function might offer "put" as an option for the first parameter, changing to "get" if a "g" is entered.
The "completion function", when actually utilised (generally via a call to shell.complete()), is passed four parameters - the shell table it is to be used with, the number of parameters entered (1, while user is typing the first; then 2, while the user is typing the second, and so on), the content of the current parameter being typed, and a numerically indexed table containing all the previous parameters typed (1 being the command name, 2 being the first parameter, and so on). In turn, the function is expected to return a numerically indexed table containing all the possible strings that could be used to complete the current parameter (or an empty table, if none are known). For example, if the user enters "pastebin p", the expected result is {"ut "}. A list of registered paths (together with their functions) can be obtained via shell.getCompletionInfo(). Other functions that may be useful in creating a "tab completion" function suitable for shell registration are fs.complete(), textutils.complete(), shell.completeProgram() and help.completeTopic(). | |
Syntax | shell.setCompletionFunction(string path, function completion function) |
Returns | nil |
Part of | ComputerCraft |
API | shell |