Saturday 15 March 2014

java - JLine example using multi word commands per line -


I can not find an example that each row using more than one command

For example, I want to write a clo like Cisco IOS, where you can have orders of many levels on one line.

e.g. The first word "show", (uses Cisco example to show list "?"), Then when you type "show" and hit tab, the next set of options are displayed.

  Like: live1 # shows? AAA Show Use of AAA Values ​​- Expression List Access Access Access List List Accounting for Access Lists Accounting Data for Active Sessions adjacency adjacent nodes .. gw1 # show ip? Access List List IP Access Lists Active IP Accounting Database Access Network Access Control Information IP Named Table ARP IP ARP Table .. gw1 # IP Interface Show? To ATM ATM interface Async Async interface BVI bridge-group virtual interface Seedima- IX CDMA Ix interface .. GW1 # show ip interface   

I use readCharacter to read one character at a time Thinking of and then once I see a space to parse the line so far.

Anyone else has had any Jline experience with this type of requirement? To

Use as

context, you can try the following behind the leading idea To merge all the options for, use the AggregateCompleter class

  list. & Lt; Completer & gt; Completors = New Linkedist & lt; Completer & gt; (); completors.add (New AggregateCompleter (New ArgumentCompleter (New StringsCompleter ( "show"), new NullCompleter ()), new ArgumentCompleter (New StringsCompleter ( "show"), new StringsCompleter ( "aaa", "access expression", "THE NEW String Compiler ("IP"), New String Complator ("Access-List", "Accounting", "String Compliment", "News String Complement", "Entry" "Alias", "ARP"), New NullCompleter () new ArgumentCompleter (new StringsCompleter ( "show"), new StringsCompleter ( "IP"), new StringsCompleter ( "interface"), new StringsCompleter ( "ATM", "async", "Biviai"), a new tap the For Mpletr ()))); (Complestr C: Aktorrs) {reader.addCompleter (c);}   

Modified Example above. After running the Java output following

  Prompt Show Show> Quick> AAA Access Access Expression Access-Lists Accounting Agnes IP Prompt & gt; Show Ip IP Prompt & gt; IP Access Lists Show Accounting Access Elias ARP Interface Prompt; Show IP Interface ATM Assign BVI prompt & gt; Show IP Interfaces ATM Async Prompt & gt; Show IP Interfaces ATM Async Prompt & gt; Show IP Interface ATM ====== & gt; "Show IP Interface ATM" soon>    

No comments:

Post a Comment