athena-framework / athena

An ecosystem of reusable, independent components
https://athenaframework.org
MIT License
211 stars 17 forks source link

Tab completion on Athena Console #293

Closed paulocoghi closed 1 year ago

paulocoghi commented 1 year ago

Hello Athena community,

I would like to ask if there is a way to intercept a "tab completion" attempt in Athena Console, in order to programmatically decide what to add/complete, if the context is appropriate.

Blacksmoke16 commented 1 year ago

At the moment, no. But the feature is planned at some point and just needs to be implemented: https://athenaframework.org/Console/Question/#Athena::Console::Question--autocompletion. Which would function similary to https://symfony.com/blog/new-in-symfony-5-4-console-autocompletion.

However, when going to execute a command, aliases may be a decent workaround. The console component is kinda smart and it'll guess what you mean and if there is no ambiguity, execute it even if its not a 100% match.

E.g. if you have commands foo:bar and foo:foo. Executing command f:f would work since there is only one possibility for it.

paulocoghi commented 1 year ago

Thanks, George

My usage scenario is a server management cli with dozens (or hundreds) of servers on the (dynamic) list, and I would like to allow the administrator to write only part of a server name and autocomplete it with tab.

Example:

$ mycli enter ath<tab>
...
$ mycli enter athenaframework.org

In this scenario, the auto completion is not to provide a known command, but a dynamic server list (completion which, of course, will be handled by a custom code).

So, the feature we are looking is a way to "intercept" an auto completion request (receiving the current context/command) and fulfill it with our own data.

Blacksmoke16 commented 1 year ago

Right, that's how the feature described in their blog post would cover this use case as well. It allows providing suggestions for particular options/arguments and leverage shell completions under the hood to tab complete those values.

E.g. a little test I did with Symfony console worked like:

Where my list of valid values athenaframework.org, google.com, and crystal-lang.org

The one gotcha seems to be since it uses shell completion features, you do need to source a generated completion file, either manually or in .profile, etc. But I think that's pretty reasonable given the benefits it provides?

EDIT: The other problem is going to be PHP is of course a dynamic lang, whereas for Crystal to generate the suggestions, it would have to compile the program on each <TAB>. Are ways around this tho so I'm sure I'll think of something.