问题
I am writing a console based Java application in which the user will be presented a custom command prompts where she can type certain commands, I want to implement an auto complete feature for the app by which while typing the command, if the user presses TAB then the command should complete. The functionality is similar to auto complete in Linux command prompt.
In Java Console App we don't get the control over TAB and a TAB pressed will by default append 8 spaces. I need some trick using which the TAB doesn't go for rendering and my app can replace the TAB with autocomplete.
Thanks in advance.
回答1:
You can try using a library like Java-Readline or jline2.
回答2:
The picocli Java command line parsing library recently added autocomplete functionality.
You may also like how it enables you to use ANSI colors and styles in the usage help message.
Disclaimer: I am the author and therefore biased.
来源:https://stackoverflow.com/questions/6961271/tab-based-autocomplete-in-console-app