Feature request: Facilitate externally-processed tab-completion
I'd like to implement tab-completion support in a shell wrapper which doesn't use readline, and I suspect that I could work directly with the array output from Psy\TabCompletion\AutoCompleter::processCallback(), so I'm wondering if you could provide a public way of obtaining those results for a given input string?
The wrapper in question already has access to its own completion framework, but I'll need to supply it with a list of completion options which I would need to obtain from PsySH.
Experimentally, I added method Shell::getTabCompletions() in src/Shell.php:
/**
* Get completion matches.
*
* @return array An array of completion matches for $input
*/
public function getTabCompletions(string $input)
{
$ac = $this->autoCompleter;
return $ac->processCallback('', null, ['line_buffer' => $input]);
}Which allows me to do this:
>>> $__psysh__->getTabCompletions('wt')
=> [
"wtf?",
"wtf",
]When the user typed TAB I would essentially then send the (as-yet-unsubmitted) input to PsySH using this new function/command, parse the output, and send the results to the local completion framework.
I feel the only thing I'd need from PsySH itself would be something along the lines of the code above. (I imagine it would work best as a PsySH command, so that simply prefixing the command name to the input would do what I wanted; but I suspect you wouldn't be so keen on this ending up in the list of standard commands, given what a niche use-case this is. I could presumably implement a custom command, however, if the basic functionality was made available?)
Source: bobthecow/psysh