How can I customize tab completion in Perl's Term::Shell? -
I am using the package to implement the CLI tool This package provides an API: comp_CMD
.
This function applies whenever the user presses the tab. My requirement is here:
Shell> Stack
TAB
Less than
`Shell> Stack Over TAB
flow sample junk
but the default comp_CMD
provides only a set of tab options such as
open> Stack
TAB Less than
`Shell> Stack Over TAB
More than
### The problem is here
Instead of over , I Want to get flow sample junk .
comp _ *
with style handler as well as against the final incomplete word Can match someone's perfection. Fortunately, however, you can get the desired results by overriding the catch_comp function like below; It gives a match against the whole command line:
My% completion_tree = (stack => gt = {gt; gt; [], over = & gt; [qw Sample junk)]}); Sub catch_comp {my $ o = shift; My ($ CMD, $ word, $ line, $ start) = @_; My $ full = substr $ line, 0, $ start; $ Full = ~ s / ^ \ s * //; My $ tree = \% completion _ tree; Foreign currency (split m '\ s +', $ finite) {if riff ($ tree) hash '(final tree); $ Tree = $ tree- & gt; {$ _}; } My @completements; $ _ = Riff ($ tree); @full = @ $ tree if / ARRA /; @compliance = keys% $ tree if / hash /; @compliance = ($ tree) if / scalar /; Return $ O-> Conclusion ($ word, [integer]); }
Comments
Post a Comment