jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 218 forks source link

Missing function to update completers #281

Closed DevCubeHD closed 6 years ago

DevCubeHD commented 6 years ago

There really should be a method to update the completer of a LineReader while it's running. Thanks!

gnodet commented 6 years ago

Could you be a bit more specific please ? I don't really understand what you want / need...

DevCubeHD commented 6 years ago

Thats hard to be more precise :D

I think a method in the LineReader to update the completer would be useful since not every implementation is static.

E.g. there are devs that can implement more commands via an API to my terminal.. the command contains its Argument nodes, but I cannot tell the reader because it does only update ist completer on initiation.

gnodet commented 6 years ago

That's a start, but I'm still not completely with you. What do you mean by update its completer ? A completer does not have to be static, for example the org.jline.builtins.Completers$Completer grabs its data from the CompletionEnvironment which can then be updated at will between calls to readline(). That's what is done in the main JLine demo, where the CompletionEnvironment is actually filled by running a set of commands : this actually happens during initialisation, but the commands are accessible from the shell and calling the complete command will actually affect the current shell completion system.

DevCubeHD commented 6 years ago

Could be that you are right but there is a chance we misunderstood each other. It is simple to find out: Can you send me an example how I add a node to a TreeCompleterafter initializing the LineReader?

gnodet commented 6 years ago

The TreeCompleter is static, but you could easily wrap it in a more dynamic completer:

    public class DelegateCompleter implements Completer {

        Completer delegate;

        @Override
        public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
            delegate.complete(reader, line, candidates);
        }

        public void setCompleter(Completer delegate) {
            this.delegate = delegate;
        }
    }

So that you can then keep a reference to that completer and call the following whenever you need

theCompleter.setCompleter(new TreeCompleter(xxx));
DevCubeHD commented 6 years ago

Thanks a lot! Your high availability for a free resource is much appreciated Sir! You are awesome! Keep on going.

DevCubeHD commented 6 years ago

//CLOSE