Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab Based Autocomplete in Console App

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.

like image 973
GJ. Avatar asked Aug 05 '11 18:08

GJ.


2 Answers

You can try using a library like Java-Readline or jline2.

like image 99
Adam Batkin Avatar answered Oct 18 '22 14:10

Adam Batkin


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.

enter image description here

Disclaimer: I am the author and therefore biased.

like image 39
Remko Popma Avatar answered Oct 18 '22 14:10

Remko Popma