peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.04k stars 132 forks source link

Print completions without common prefix? #153

Closed nights99 closed 2 years ago

nights99 commented 2 years ago

Raising as an issue not a PR, as I'm not quite sure about the request; I am happy to implement.

I have completions that can get very lengthy; even a short example might be:

(This is with SetTabCompletionStyle(liner.TabPrints))

netconf> get-conf openconfig-lldp lldp 
get-conf openconfig-lldp lldp interfaces get-conf openconfig-lldp lldp config get-conf openconfig-lldp lldp state 

In my case I can expect the user to know enough of the context that just printing the final word without the common prefix makes sense:

netconf> get-conf openconfig-lldp lldp 
config state interfaces 

Does this make sense as a possible change (presumably under an option), or have I just misundertood how this is supposed to work?

Thanks, Jon

peterh commented 2 years ago

Yes, that makes sense as a possible change. Frankly, I'm a little surprised it doesn't work that way already. (To be honest, I've never used TabPrints in any of my own projects).

Taking a closer look, it appears that it does work the way you want if you use SetWordCompleter instead of SetCompleter. Presumably you would implement this by enhancing the anonymous function generated inside SetCompleter? (Or maybe you'll say "Oh, SetWordCompleter" and forget about implementing anything in liner. I'm okay with that to.)

If you do implement this change, I wouldn't bother adding an option. It doesn't make sense to print prior words when completing the current word, so there's no reason to have an option to make it keep the old (current) broken behaviour.

nights99 commented 2 years ago

Thanks Peter; I think its definitely worth me taking a proper look at SetWordCompleter first, though it might take a week or two before I get chance.

Fwiw, I think the main reason I'm using SetCompleter is because I'd migrated from another package, and using that minimised my changes; but I think SetWordCompleter probably actually matches what I actually need better.

nights99 commented 2 years ago

OK, yep, I'm going with the option of moving to SetWordCompleter and leaving liner alone :)

Thanks for the advice, and for providing this package; I'll go ahead and close the issue.