1 19 package jline.example; 20 21 import jline.*; 22 import java.io.*; 23 import java.util.*; 24 import java.util.zip.*; 25 26 public class Example 27 { 28 public static void usage () 29 { 30 System.out.println ("Usage: java " + Example.class.getName () 31 + " [none/simple/files/dictionary]"); 32 System.out.println (" none - no completors"); 33 System.out.println (" simple - a simple completor that comples " 34 + "\"foo\", \"bar\", and \"baz\""); 35 System.out.println (" files - a completor that comples " 36 + "file names"); 37 System.out.println (" dictionary - a completor that comples " 38 + "english dictionary words"); 39 System.out.println (" classes - a completor that comples " 40 + "java class names"); 41 } 42 43 44 public static void main (String [] args) 45 throws IOException 46 { 47 ConsoleReader reader = new ConsoleReader (); 48 reader.setDebug (new PrintWriter (new FileWriter ("writer.debug", 49 true))); 50 51 if (args == null || args.length == 0) 52 { 53 usage (); 54 return; 55 } 56 57 List completors = new LinkedList (); 58 for (int i = 0; args != null && i < args.length; i++) 59 { 60 if (args [i].equals ("none")) 61 { 62 } 63 else if (args [i].equals ("files")) 64 { 65 completors.add (new FileNameCompletor ()); 66 } 67 else if (args [i].equals ("classes")) 68 { 69 completors.add (new ClassNameCompletor ()); 70 } 71 else if (args [i].equals ("dictionary")) 72 { 73 completors.add ( 74 new SimpleCompletor (new GZIPInputStream ( 75 Example.class.getResourceAsStream ("english.gz")))); 76 } 77 else if (args [i].equals ("simple")) 78 { 79 completors.add ( 80 new SimpleCompletor ( 81 new String [] { "foo", "bar", "baz"})); 82 } 83 else 84 { 85 usage (); 86 return; 87 } 88 } 89 90 reader.addCompletor (new ArgumentCompletor (completors)); 91 92 93 String line; 94 PrintWriter out = new PrintWriter (System.out); 95 96 while ((line = reader.readLine ("prompt> ")) != null) 97 { 98 out.println ("======>\"" + line + "\""); 99 out.flush (); 100 } 101 } 102 } 103 | Popular Tags |